我正在尝试从网页中提取文本,然后将所有文本都转换为小写字母,但是我a,出现object has no attribute
错误。可以解决吗?
import requests
from bs4 import BeautifulSoup as bs
import operator
def webpage(url):
word_list = []
soup = bs(requests.get(url).text, 'html.parser')
for text in soup('p', {'class': 'PE7lZb'}):
content = text.string
words = content.lower().split()
webpage("https://godan.business.site/")
答案 0 :(得分:0)
这里的内容与str的类型不同。您应在调用.lower()之前检查内容是否存在
content = text.string
words = content.lower().split() if content and isinstance(content,str) else None