使用.text从标记中获取文本。
oname = soup.find("title")oname.text要不就
soup.title.text
In [4]: from bs4 import BeautifulSoup In [5]: import requestsIn [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.textOut[7]: u'html - How to Retrieve information inside a tag with python - Stack Overflow'要打开文件并使用文本作为名称,请像使用其他任何字符串一样简单地使用它:
with open(oname.text, 'w') as f



