本文主要是介绍ResultSet object has no attribute '%s'. You're probably treating a list of elements like a single e,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
"ResultSet object has no attribute ‘%s’. You’re probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute ‘text’. You’re probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
查看是否该使用find()方法的地方使用了find_all()方法,当不是一个单独的对象的时候不能使用.text方法
我错误的代码:
最后一行报错了,其实问题在倒数第二行,这里的标签‘a’是一个单独的对象,但我使用了find_all()方法,这样使用是错误的,应改成find()
正确的代码:
import requests
from bs4 import BeautifulSoup
res=requests.get('http://books.toscrape.com/')
html=res.text
soup=BeautifulSoup(html,'html.parser')
items=soup.find('ul',class_='nav nav-list').find_all('li')
for item in items:name=item.find('a')print(name.text.strip())
这篇关于ResultSet object has no attribute '%s'. You're probably treating a list of elements like a single e的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!