I'm trying to extract the text inside from the following html structure:
<div class="account-age">
<label></label>
<div>
<div>
<span>Text to extract</span>
</div>
</div>
</div>
I have the following Beautiful Soup code to do it:
from bs4 import BeautifulSoup as bs
soup = bs(html, "lxml")
div = soup.find("div", {"class": "account-age"})
span = div.children[1].children[0].children[0]
text = span.get_text()
Unfortunately, Beautiful Soup is throwing the error: 'list_iterator' object is not subscriptable. How can I fix this to extract the text I need?
You might do this by directly chaining the tags from the root div:
div.div.div.span.get_text()
# u'Text to extract'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With