问题:练习BeautifulSoup的时候练习代码爬大麦网的演唱会信息。使用过一次find_all 后,在循环中不能再次使用findall了
代码:
from bs4 import BeautifulSoup
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://search.damai.cn/search.htm?spm=a2oeg.home.category.ditem_0.591b23e11hVMUT&ctl=演唱会&order=1&cty=北京')
html = browser.page_source
soup = BeautifulSoup(html, 'lxml')
perform_list = soup.find_all(class_='items')
perform_dict = []
for perform_item in perform_list:
show_name = perform_item.find(class_='items__txt__title').find('a').string
show_time_text = perform_item.find_all(class_='items__txt__time').text
提示:
show_time_text = perform_item.find_all(class_='items__txt__time').text
File "E:\python document\Test\venv\lib\site-packages\bs4\element.py", line 1602, in getattr
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. 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 items like a single item. Did you call find_all() when you meant to call find()?
请问是为什么呢?