簡體   English   中英

使用python selenium驅動下載pdf文件

[英]Using python selenium driver to download pdf file

我正在嘗試從鏈接steel下載 pdf 文件(“下載產品目錄”)。 使用 python xpath 來實現這一點。 但得到語法錯誤。 嘗試了所有排列和組合。 我嘗試過的代碼如下:

    import time
    from selenium import webdriver
    driver = webdriver.Chrome('c:/windows/chromedriver.exe')  # Optional argument, if not specified will search path.
    driver.get("https://sail.co.in/en/products/sail-structural-sections")
    time.sleep(5) # Let the user actually see something!
    elem =driver.find_element_by_xpath('//a[text()='Download Product Catalogue']//parent::div[@class='toppdf_brochure pdfbrochure']')
    elem.click()
    time.sleep(5) # Let the user actually see something!
    driver.quit()

試試這個xpath

elem =driver.find_element_by_xpath("//*[contains(text(), 'Download Product Catalogue')]")

完整代碼:

import time
from selenium import webdriver
driver = webdriver.Chrome('c:/windows/chromedriver.exe')  # Optional argument, if not specified will search path.
driver.get("https://sail.co.in/en/products/sail-structural-sections")
time.sleep(5) # Let the user actually see something!
elem =driver.find_element_by_xpath("//*[contains(text(), 'Download Product Catalogue')]")
elem.click()
time.sleep(5) # Let the user actually see something!
driver.quit()

瀏覽器截圖:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM