【问题标题】:I'm trying to build a web scraper and can only pull one css element right now where there are 81我正在尝试构建一个网络爬虫,现在只能拉一个有 81 个 CSS 元素
【发布时间】:2021-04-26 13:54:26
【问题描述】:

我想提取所有 81 个元素,但一次只能提取一个。该页面是动态的,因此我将拥有超过 81 个元素。该页面还有几个sortableTable-numberattributes,所以我尽量避免使用它,因为beautifulsoup 似乎会感到困惑。

rreads1 = soup.select('tr.sortableTable-row:nth-child(2) > td:nth-child(3) > span:nth-child(2)')
rreads = rreads1[0].get_text()
reads.append(rreads)

【问题讨论】:

标签: python web web-scraping beautifulsoup


【解决方案1】:

如前所述,改进您的问题并添加MRP

根据提供的信息,您可以循环 macthes:

reads = []

for item in soup.select('tr.sortableTable-row:nth-child(2) > td:nth-child(3) > span:nth-child(2)'):
    rreads = item.get_text()
    reads.append(rreads)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2016-07-18
    • 1970-01-01
    相关资源
    最近更新 更多