【问题标题】:Web Scraping AttributeError [duplicate]Web Scraping AttributeError [重复]
【发布时间】:2016-12-17 09:41:38
【问题描述】:

我正在尝试使用 BeautifulSoup 在网站上获取具有特殊 ID 的号码。这是我的代码

from urllib2 import urlopen
from bs4 import BeautifulSoup
import requests, logging
logging.basicConfig()
html = urlopen("http://example.com")
bsObj = BeautifulSoup(str(html), "html.parser")
select = bsObj.findAll(id="myid")
print(select.get_text())

但我得到了“AttributeError:“ResultSet”对象没有属性“get_text”。 问题出在哪里?

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    ResultSet 有点像一个列表,所以你需要做select[0].get_text() 之类的。

    更多:Beautiful Soup: 'ResultSet' object has no attribute 'find_all'?

    【讨论】:

    猜你喜欢
    • 2019-06-04
    • 2020-05-25
    • 2021-09-03
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    相关资源
    最近更新 更多