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选项并打印页面This is the option it should select
答案 0 :(得分:0)
使用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,
}