【问题标题】:Unable to find a way to access downloadable element from page无法找到从页面访问可下载元素的方法
【发布时间】:2020-12-13 19:36:30
【问题描述】:

我想以编程方式从篮球参考网下载 CSV 文件。下面的屏幕截图显示了如何在浏览器中手动完成:

但是,该元素的页面来源如下:

我的第一个想法是这不是可抓取的,因为它在一些 Javascript 或其他东西的后面。有没有办法让我了解这个元素?

更新:这也存在:

我可以让 Selenium 点击这个吗?

【问题讨论】:

  • 你有网址吗?

标签: python html selenium xpath web-scraping


【解决方案1】:

如果您想单击该元素并显示表格,您可以这样做。但这只会在网站上显示它,因此如果您愿意,可以抓取它或向页面发送请求。

driver.get('https://www.basketball-reference.com/teams/')
wait=WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Share & more']/parent::li"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Get table as CSV (for Excel)']"))).click()

导入

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

【讨论】:

  • 谢谢 - 我会考虑添加这些。这看起来正是我正在寻找的。但本质上,我们知道它可以通过 Selenium 进行点击?
  • 我收到了这个:ElementClickInterceptedException: Message: element click intercepted: Element <li class="hasmore">...</li> is not clickable at point (239, 573). Other element would receive the click: <iframe id="google_ads_iframe_....
  • 在阅读更多内容时,看起来这可能是谷歌广告的阻碍。到目前为止,我无法弄清楚如何适当地删除它。
  • 它可以通过 selenium 点击。如果有谷歌广告,您可能可以通过选项执行某些操作,或者只需单击 x。
猜你喜欢
  • 2019-05-04
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
相关资源
最近更新 更多