使用python硒驱动程序下载pdf文件

时间:2020-11-01 14:07:54

标签: python selenium pdf download

我正在尝试从链接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()

1 个答案:

答案 0 :(得分:1)

尝试以下/authenticate

xpath

完整代码:

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

浏览器屏幕截图:

enter image description here