![](/img/trans.png)
[英]Selenium Webdriver: How to Download a PDF File with Python?
[英]How to automatically download a PDF file with selenium in python when it is open on another browser page
我正在單擊帶有 selenium 的鏈接,它打開了帶有 PDF 的新瀏覽器選項卡,我想知道是否有辦法下載 PDF,我不在乎瀏覽器選項卡是否打開然后開始下載,我想要的是下載那個PDF。
謝謝
你可以使用 pyautogui 和選項
import pyautogui
from selenium.webdriver.chrome.options import Options
DRIVER_PATH = r'chromedriver.exe' //chromedriver path
chrome_options = Options()
chrome_options.add_experimental_option('prefs', {
"download.default_directory": "C:/Users", #Change default directory for downloads
"download.prompt_for_download": False, #To auto download the file
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True #It will not show PDF directly in chrome
})
driver = webdriver.Chrome(executable_path=DRIVER_PATH,options = chrome_options)
driver.get(url) //url of pdf
time.sleep(3)
pyautogui.press('enter')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.