使用 python selenium 驱动程序下载 pdf 文件
Using python selenium driver to download pdf file
我正在尝试从 link steel 下载 pdf 文件 ('DOWNLOAD PRODUCT CATALOGUE')。使用 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()
浏览器截图:
我正在尝试从 link steel 下载 pdf 文件 ('DOWNLOAD PRODUCT CATALOGUE')。使用 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()
浏览器截图: