Answer the question
In order to leave comments, you need to log in
Why is find_all not working?
I welcome everyone! ran into a problem while parsing. My code
def parse():
url = 'kolesakz.html'
page = open(url, encoding='utf-8')
soup = BeautifulSoup(page.read(), 'html.parser')
items = soup.find_all('div', class_ = 'result-block col-sm-8')
comps = []
for item in items:
comps.append({
'title': item.find_all('span', class_ = 'a-el-info-title').get_text(strip = True)
})
for comp in comps:
print(comp['title'])
parse()`
Traceback (most recent call last):
File "C:\Users\90536\Desktop\123\bot.py", line 19, in <module>
parse()
File "C:\Users\90536\Desktop\123\bot.py", line 14, in parse
'title': item.find_all('span', class_ = 'a-el-info-title').get_text(strip = True)
File "C:\Users\90536\AppData\Local\Programs\Python\Python39\lib\site-packages\bs4\element.py", line 2173, in __getattr__
raise AttributeError(
AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
Answer the question
In order to leave comments, you need to log in
'title': item.find_all('span', class_ = 'a-el-info-title').get_text(strip = True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question