python - get text oustside tags using Beautifulsoup -
i new , having hard time getting specific text outside of tags using beautifulsoup.
here code:
from bs4 import beautifulsoup soup = beautifulsoup(''' <li id="salesrank" style="list-style : none"> <b>sellers rank:</b> #81 in fun (<a href="http://www.google.com">see top 100</a>) </li> ''') therank = soup.find('li', attrs={'id':'salesrank'}).find('b', text="sellers rank:") print therank.find_next_sibling().text.strip()
i trying #81 in fun
the full text element after <b>
tag include (
opening parenthesis.
use .next_sibling
attribute next object given tag:
>>> soup.find('li', attrs={'id':'salesrank'}).find('b', text="sellers rank:") <b>sellers rank:</b> >>> soup.find('li', attrs={'id':'salesrank'}).find('b', text="sellers rank:").next_sibling u' \n #81 in fun\n ('
Comments
Post a Comment