51Testing软件测试论坛

标题: Selenium Python 爬取 pdf 文件时怎么点击 Chrome 浏览器上的下载按钮 [打印本页]

作者: 测试积点老人    时间: 2022-4-18 09:55
标题: Selenium Python 爬取 pdf 文件时怎么点击 Chrome 浏览器上的下载按钮
用 Selenium 爬取 pdf 文件,想要自动点击 Chrome 浏览器上的下载按钮,但是XPath 找不到那个按钮,请问怎么解决?
  1. import os
  2. import csv
  3. import time
  4. import random
  5. import requests

  6. from selenium import webdriver
  7. from selenium.webdriver.common.by import By
  8. from selenium.webdriver.support.ui import WebDriverWait
  9. from selenium.webdriver.support import expected_conditions as ec

  10. driver = webdriver.Chrome()
  11. driver.get("https://stanford.edu/~dkim04/assets/pdf/hartshorne/001.pdf")

  12. download_button = WebDriverWait(driver, 10).until(
  13. ec.presence_of_element_located((By.ID, 'download'))
  14. )
  15. download_button.click()
复制代码
运行结果及报错内容
  1. Traceback (most recent call last):
  2. File "C:/Users/ChenHaoHai/Desktop/scrap2.py", line 17, in
  3. download_button = WebDriverWait(driver, 10).until(
  4. File "C:\Users\ChenHaoHai\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
  5. raise TimeoutException(message, screen, stacktrace)
  6. selenium.common.exceptions.TimeoutException: Message:
  7. Stacktrace:
  8. Backtrace:
  9. Ordinal0 [0x00AD06F3+2492147]
  10. Ordinal0 [0x00A69BD1+2071505]
  11. Ordinal0 [0x00972478+1057912]
  12. Ordinal0 [0x0099C964+1231204]
  13. Ordinal0 [0x009C6B62+1403746]
  14. Ordinal0 [0x009B57FA+1333242]
  15. Ordinal0 [0x009C4F38+1396536]
  16. Ordinal0 [0x009B568B+1332875]
  17. Ordinal0 [0x009921D4+1188308]
  18. Ordinal0 [0x0099302F+1191983]
  19. GetHandleVerifier [0x00C567A6+1545030]
  20. GetHandleVerifier [0x00D0105C+2243580]
  21. GetHandleVerifier [0x00B5BC97+518199]
  22. GetHandleVerifier [0x00B5AD80+514336]
  23. Ordinal0 [0x00A6ED2D+2092333]
  24. Ordinal0 [0x00A72EE8+2109160]
  25. Ordinal0 [0x00A73022+2109474]
  26. Ordinal0 [0x00A7CB71+2149233]
  27. BaseThreadInitThunk [0x7637FA29+25]
  28. RtlGetAppContainerNamedObjectPath [0x77C57A7E+286]
  29. RtlGetAppContainerNamedObjectPath [0x77C57A4E+238]
复制代码



作者: qqq911    时间: 2022-4-19 12:01
获取连接
作者: kallinr    时间: 2022-4-19 12:36
不可能
作者: jingzizx    时间: 2022-4-19 14:33
浏览器本身的还是哪部分的内容




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2