繁体   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