I have this span and I want to get the title
<span title="Something"></span>
How to get that with beautifulsoup?
res = soup.find('span')
print res //Was trying to add res.title but result is 'None'
You should be able to access it like this:
res = soup.find('span')['title']
Docs
Edit: I shoudl clarify, res would then be the value of the title attribute. If you want the element to use later, change my code to:
res = soup.find('span')
title = res['title']
Then you could keep using res (if needed).
Also, .find is going to return a single element. You'll want to make sure it is the span you want, since the HTML could have more than one span.
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