beautifulsoup - Is there a shorter syntax than soup.select("#visitor_stats")[0]? -


i'm using beautifulsoup (import bs4) read information web page. several lines in script like

stats = soup.select("#visitor_stats")[0] 

is there shorter syntax this?

select() lets select bunch of html tag elements based on css properties (like id , class). in case looking html tag elements css id property set visitor_stats. , selecting first element returned list.

the beautifulsoup method find() returns first occurrence of search criteria. list index [0] can gotten rid of using find()

stats = soup.find(attrs={'id':'visitor_stats'}) 

but not sure if shorter :)


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -