【问题标题】:Getting "Show More Reviews" text using Selenium使用 Selenium 获取“显示更多评论”文本
【发布时间】:2021-05-19 12:46:21
【问题描述】:

我试图在https://www.capterra.com/p/155563/Freshsales/reviews/ url 上的“显示更多评论”之后获取 HTML 页面的来源,但我什至无法获取部分数据。

我已经能够解析所有具有不同链接和点击的数据,这些数据打开了不同的页面,但相同的页面数据却超出了我的范围。不是 HTML 人,所以理解按钮点击有点困难。

读了几篇文章后,我认为这个任务用漂亮的汤是不可能的,所以必须用 Selenium 来完成。请推荐

我正在分享图片,之后我想获取数据。

【问题讨论】:

  • 请提供您尝试点击按钮的代码
  • 用你的代码试验更新问题。

标签: selenium web-scraping beautifulsoup selenium-chromedriver web-crawler


【解决方案1】:

您可以使用 xpath 或 css:

xpath:

//div[contains(@class,"MoreReviewButton")]/button

CSS

div[class *= MoreReviewButton] > button

两者是相等的,并且正在搜索包含带有“MoreReviewButton”的类的div元素,然后在其中找到直接按钮子元素。但是该页面似乎需要双击并且不能单击:

所以使用:

elem = driver.find_element_by_css_selector("div[class *= MoreReviewButton] > button")

driver.execute_script("arguments[0].scrollIntoView()",elem)   


a = WebDriverWait(driver, 20).until(EC.visibility_of_element_located(
    (By.CSS_SELECTOR, "div[class *= MoreReviewButton]>button")))

ActionChains(driver).move_to_element(a).double_click().perform()

elem = driver.find_element_by_css_selector("div[class *= MoreReviewButton] > button")

driver.execute_script("arguments[0].scrollIntoView()",elem)   


a = WebDriverWait(driver, 20).until(EC.visibility_of_element_located(
    (By.CSS_SELECTOR, "div[class *= MoreReviewButton]>button")))

a.click()
a.click()

【讨论】:

  • 我尝试了你的方式,但我一直在 "elem = driver.find_element_by_css_selector("div[class *= MoreReviewButton] > button")" 处得到无类型元素但是我现在已经解决了这个问题简单的 API 获取请求,我可以在其中获取所有详细信息!谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 2015-07-13
  • 2020-08-29
  • 2011-10-02
  • 1970-01-01
相关资源
最近更新 更多