【问题标题】:How to scrape a page and then perform a button click to go to next page for scraping using Selenium and BeautifulSoup如何使用 Selenium 和 BeautifulSoup 抓取页面然后执行按钮单击以转到下一页进行抓取
【发布时间】:2019-09-30 19:37:14
【问题描述】:

我正在抓取一个网页,该网页有一个带有子 tr 和 td 标签的表格。我能够正确地刮掉第一页。但是要转到下一页,我需要单击按钮。我需要一些帮助来理解这一点。我正在使用 Selenium 和 Beautiful soup 来获得页面响应。

按钮标签的html如下:

<input type="submit" name="RadGrid1$ctl00$ctl03$ctl01$ctl28" value=" " onclick="return false;" title="Next Page" class="rgPageNext">

我试过的示例代码:

for i in range(0,14):

  # code for scraping 1 page

   some code here

   btn = driver.find_element_by_xpath(xpath)

   btn.click()

按钮单击转到下一页,但无法抓取 2-14 页中的任何一个的信息。我尝试将我的抓取 1 页代码放在一个 for 循环中,并在最后添加了按钮单击逻辑。它会抓取第一页,执行按钮单击,但不会进入下一页。相反,它会循环回到第 1 页。

【问题讨论】:

  • 可以分享网址吗?

标签: python-3.x selenium beautifulsoup


【解决方案1】:

至于我能理解的,我认为你还没有更新 Beautifulsoup 的新 url。单击后,您获取新页面的当前 url,然后执行抓取。然后只有它会抓取新页面,否则它会包含旧页面的 url,因此只会抓取该页面。

【讨论】:

    猜你喜欢
    • 2020-08-23
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    相关资源
    最近更新 更多