我正在开发一个网络抓取程序来下载这些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)