Python Selenium重命名下载PDF

时间:2017-05-22 22:48:49

标签: python selenium pdf web-scraping selenium-chromedriver

我正在开发一个网络抓取程序来下载这些pdf文档的最新版本,并且在尝试找出如何在下载之前重命名pdf文件时遇到了麻烦。任何帮助都会被赞赏,这是我的代码。

import time
import sys
from selenium import webdriver

url  = 'http://aogweb.state.ak.us/WebLink/0/doc/18690/Page1.aspx'
options = webdriver.ChromeOptions()
tgt = "G:\Well Schematics\Well Histories"
profile = {"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}],"download.default_directory" : tgt, "download.prompt_for_download": False, "download.directory_upgrade": True }
options.add_experimental_option("prefs",profile)
chrome = webdriver.Chrome(chrome_options = options)
chrome.get(url)
time.sleep(3)
chrome.find_element_by_id('PdfDialog_PdfDownloadLink').click()
time.sleep(2)
chrome.find_element_by_name('PdfDialog:PageRangeBox').clear()
chrome.find_element_by_name('PdfDialog:PageRangeBox').send_keys('1-30')
chrome.find_element_by_name('PdfDialog:download').click()
time.sleep(5)

0 个答案:

没有答案