[英]How to fix error: AttributeError: 'str' object has no attribute 'text'
[英]how to fix for the "AttributeError: 'str' object has no attribute 'content' "python error
这是我使用的代码。
n=0
link = coverpage_news[n]['href']
title = coverpage_news[n].get_text()
article = url.read()
article_content = article.content
soup_article = BeautifulSoup(article_content, 'html5lib'
但它显示一条错误消息“AttributeError:'str'对象没有属性'内容',请谁能帮助我。
当您将 html 源代码输入到 BeautifulSoup 对象中时,您希望将其作为字符串输入。 由于您在使用url.read()
时已经将其作为字符串,因此无需将其转换为带有.content
的字符串,因此出现错误, str
上没有content
属性。 只需删除该行即可解决问题。
n=0
link = coverpage_news[n]['href']
title = coverpage_news[n].get_text()
article_content = url.read()
soup_article = BeautifulSoup(article_content, 'html5lib')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.