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
Post a Comment