python-3.x - Chromedriver另存为PDF方法不起作用
问题描述
Chromedriver 另存为 PDF 方法不起作用。在它工作正常之前,但现在每当我运行此代码时,它都会进入另存为 PDF 屏幕并实际打印页面而不是另存为 PDF
我尝试更改ID,但它也没有奏效
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"margin": 0,
'size': 'auto'
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
"margin": 0,
'size': 'auto'
}
profile = {'printing.print_preview_sticky_settings.appState': json.dumps(
appState)}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')
driver = webdriver.Chrome(chrome_options=chrome_options)
它应该将文件保存为 PDF 而不是选择 Microsoft XPS Document Writer 选项并打印页面 这是它应该选择的选项
解决方案
使用 Chrome 版本 78.0.3904.108(官方版本)(64 位)。
添加"account": ""
到"recentDestinations"
.
appState = { "recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": "", # <======= Add this
}],
"selectedDestinationId": "Save as PDF",
"version": 2,
}
推荐阅读
- angular - then() 在 promise.all() 解决之前首先运行
- css - 清除内联块而不在它们之间使用空的 div.clear?
- swift - UITableView 滚动到框架外
- android - 如何使用 Object Animator 制作放大动画
- amazon-web-services - 从 AWS SES 发送电子邮件时出现凭证错误
- javascript - jQuery验证错误信息定位很奇怪
- c - c - 用空终止符覆盖换行符转义字符会导致段错误
- r - 查看路口附近的地块
- sql-server - SQL Server 动态 groupby 数据透视
- r - 如何应用于矩阵列表中第 j 个矩阵的每个第 i 列