How to get inner text value of an HTML tag with BeautifulSoup bs4?

Use .text to get the text from the tag.

oname = soup.find("title")
oname.text

Or just soup.title.text

In [4]: from bs4 import BeautifulSoup    
In [5]: import  requests
In [6]: r = requests.get("http://stackoverflow.com/questions/27934387/how-to-retrieve-information-inside-a-tag-with-python/27934403#27934387")    
In [7]: BeautifulSoup(r.content).title.text
Out[7]: u'html - How to Retrieve information inside a tag with python - Stack Overflow'

To open a file and use the text as the name simple use it as you would any other string:

with open(oname.text, 'w') as f

Leave a Comment