【问题标题】:Download file from browser using selenium in Python在 Python 中使用 selenium 从浏览器下载文件
【发布时间】:2021-08-03 23:24:40
【问题描述】:

我知道这个问题已被问过几次,但针对已发布问题的解决方案对我的情况没有帮助。

我想从这个网站下载一个数据集: https://datadashboard.fda.gov/ora/cd/inspections.htm

我必须单击“数据集”,然后单击下拉列表中的“整个检查数据集”以下载我需要的数据集。

这是“数据集”的 HTML:

这是“整个检查数据集”的 HMTL:

这是我获取数据集的代码:

iconDownload = driver.find_element_by_xpath('//*[@id="expand-d"]').click()
WebDriverWait(driver, 60).until(expected_conditions.visibility_of_element_located((By.ID, "expand-d")))

downloadDataset = driver.find_element_by_xpath('//*[@id="exp-dt1"]')
downloadDataset.click()

WebDriverWait(driver, 120, 1).until(checkDownload)

我也试过了:

    iconDownload = driver.find_element_by_css_selector("span[class=\'icon-download\']").click()

但我收到此错误:

文件“FDAComplianceDashboardInspections-GetFileHash.py”,第 68 行,在 saveSearchResults 中 iconDownload = driver.find_element_by_xpath('//*[@id="expand-d"]').click() 文件“/home/devuser/code/data-sourcing/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py”,第 80 行,点击 self._execute(Command.CLICK_ELEMENT) _execute 中的文件“/home/devuser/code/data-sourcing/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py”,第 633 行 return self._parent.execute(命令,参数) 文件“/home/devuser/code/data-sourcing/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py”,第 321 行,在执行 self.error_handler.check_response(响应) 文件“/home/devuser/code/data-sourcing/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py”,第 242 行,在 check_response 引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.WebDriverException:消息:未知错误:元素在点(400、759)不可点击 (会话信息:无头 chrome=65.0.3325.181) (驱动信息:chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 5.10.25-linuxkit x86_64)

注意:我尝试了 find_element_by_id、find_element_by_class、find_element_by_css_selector,但没有任何效果。

这是我第一次使用 selenium,非常感谢帮助解决这个问题。

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    你能检查一下吗,希望它对你有用

    driver.get("https://datadashboard.fda.gov/ora/cd/inspections.htm")
    driver.maximize_window()
    
    driver.find_element_by_id("expand-d").click()
    driver.execute_script("window.scrollBy(0,400)");
    time.sleep(15)
    driver.find_element_by_link_text("Entire Inspections Dataset").click()
    

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2018-05-21
      • 1970-01-01
      • 2014-10-27
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多