python的selenium如何下载pdf⽂件
1.近期下载⼀些数据,涉及到pdf⽂件,因⼀些原因,需要⽤到selenium,希望不是在浏览器中打开pdf,⽽是下载这个⽂件# -*- coding: utf-8 -*-
import time
import re
import io
from selenium import webdriver
from selenium.webdrivermon.action_chains import ActionChains
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
option = webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ['enable-automation'])
option.add_experimental_option('prefs', {
"download.default_directory": "D:\\edesk\\outtask\\AIopt\\AIOPTjiaofu\\lunwen",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True #这句配置很重要
}
)
driver = webdriver.Chrome(chrome_options=option)
wait = ui.WebDriverWait(driver,20)
selenium获取cookie<("xxxxx1-s2.0-S2095495621000383-main.pdf")
time.sleep(10)
driver.set_window_size(width=1000, height=800, windowHandle="current")
flag = False
if not flag:
#可以⼿动输⼊⼀次密码,后⾯访问均有cookie
raw_input('login:')
print "login"
time.sleep(10)
<("xxxxx1-s2.0-S2095495621000383-main.pdf")
time.sleep(20)
print "download"
driver.quit()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论