python - how to display text only using find_all in beautiful soup? -
there succinct solution displaying text div using beautiful soup , find
here https://stackoverflow.com/a/8994150/1063287 :
result = soup.find('div', {'class' :'flagpagetitle'}).text
i wanting apply same logic in scenario where:
content = original_content("div","class1 class2")
if modify be:
content = original_content("div","class1 class2").text
i getting error:
attributeerror: 'resultset' object has no attribute 'text'
can please tell me how can use same logic shown in scenario using find_all above? (note using shortcut of find_all
not type it, see here)
thank you.
you using implied .find_all()
method when call element directly, returns result set (a list-like object). using limit
not change returned, how many returned.
if want first element of set, use slicing:
original_content("div","class1 class2", limit=1)[0].text
or explicit , use .find()
instead:
original_content.find("div","class1 class2").text
to text of matches you'll need loop on result set. list comprehension easiest:
[el.text el in original_content("div","class1 class2")]
Comments
Post a Comment