appleguess 2019-11-27 02:49 采纳率: 0%
浏览 1420

使用过一次find_all 后,在循环中不能再次使用findall了

问题:练习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()?

请问是为什么呢?

  • 写回答

1条回答 默认 最新

  • 繁华三千东流水 2019-11-27 08:44
    关注

    find_all 获得的是一个列表 你可以指定列表中的一个元素.text试一试。如:perform_item.find_all(class_='items__txt__time')【0】.text

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况