【发布时间】:2020-07-28 17:12:04
【问题描述】:
链接到我要抓取的页面:
https://www.nytimes.com/reviews/dining
因为这个页面有一个“显示更多”按钮,我需要 Selenium 自动迭代地点击“显示更多”按钮,然后以某种方式使用 Beautiful soup 来获取页面上每个餐厅评论的链接。在下面的照片中,我要收获的链接位于 https://...onigiri.html">。
到目前为止的代码:
url = "https://www.nytimes.com/reviews/dining"
driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
driver.get(url)
for i in range(1):
button = driver.find_element_by_tag_name("button")
button.click()
如何使用 WebDriverWait 和 BeautifulSoup [BeautifulSoup(driver.page_source, 'html.parser')] 来完成这个任务?
【问题讨论】:
-
您能否更具体地说明您正在努力解决的问题?顺便说一句,你可能不需要 BeautifulSoup。
-
你试过什么?您是否看过其他使用 WebDriverWait 的示例?您要抓取哪些链接?您很可能只使用 Selenium 来获取它们,而根本不需要 BeautifulSoup。
-
@AMC 是的!我刚刚在我的问题中添加了一张照片,以进一步阐明我要抓取哪些链接。
-
@Code-Apprentice 我试过查看 WebDriverWait 文档——有 find_element_by_tag_name、x_path、css_selector 之类的东西,但我不太确定如何应用我在互联网解决了我的特殊问题。
标签: python selenium-webdriver web-scraping beautifulsoup