2 回答
TA贡献1869条经验 获得超4个赞
基本上在这一行:
item = items.find("image:title").text
items.find("image:title")返回None(可能是因为find在 中找不到您期望的内容items)。那么因为None没有属性text然后(None).text引发错误AttributeError: 'NoneType' object has no attribute 'text'
如果要修复错误,可以执行以下操作:
item = items.find("image:title")
if item:
title = item.text # you can use other variable name if you want to.
else:
print("there is no image:title in items")
TA贡献1827条经验 获得超8个赞
您的第一个文本返回,None因此您收到此错误。在尝试获取文本之前,您需要检查 item 是否为 none。
for items in soup.find_all("url"):
getTitle = items.find('image:title')
if getTitle is not None:
item = getTitle.text
url = items.find("loc").text
print (item,url)
添加回答
举报
