我正在嘗試從https://www.axisbank.com/interest-rate-on-deposits?cta=homepage-rhs-fd鏈接下載 pdf,以下代碼僅打開網站并單擊下載鏈接,但我無法下載pdf Python代碼
print("Helllo Pratik")
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {
"download.default_directory": "D:\\pdf_download",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True
})
driver = webdriver.Chrome('D:\driver_chrome\chromedriver.exe',options=options)
driver.get("https://www.axisbank.com/interest-rate-on-deposits?cta=homepage-rhs-fd")
element=driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div[2]/a/div/div/span")
element.click()
driver.quit()
uj5u.com熱心網友回復:
要從網站下載國內定期存款pdf,您需要點擊element_to_be_clickable()的誘導WebDriverWait的元素,您可以使用以下定位器策略:
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option('prefs', {
"download.default_directory": "C:\\Datafiles",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True
})
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://www.axisbank.com/interest-rate-on-deposits?cta=homepage-rhs-fd")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Domestic Fixed Deposits']//following-sibling::div[1]/span"))).click()
注意:您必須添加以下匯入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
瀏覽器快照:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/488588.html
標籤:Python 硒 硒网络驱动程序 路径 网络驱动程序等待
上一篇:Xamarin:“CustomBottomNavAppearance”未實作介面成員“IShellBottomNavViewAppearanceTracker.SetAppearance[...]”錯
