有人知道如何在使用selenium打印时禁用“页眉和页脚”选项吗?默认设置为true,有人知道如何修复吗?谢谢你
import json
import os
from selenium import webdriver
# setting html path
htmlPath = os.getcwd() + "\\sample.html"
addr = "file:///" + htmlPath
# setting Chrome Driver
chromeOpt = webdriver.ChromeOptions()
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account": ""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2
}
prefs = {
'printing.print_preview_sticky_settings.appState': json.dumps(appState)}
chromeOpt.add_experimental_option('prefs', prefs)
chromeOpt.add_argument('--kiosk-printing')
driver = webdriver.Chrome('.\\bin\\chromedriver', options=chromeOpt)
# HTML open and print
driver.get(addr)
driver.execute_script('return window.print()')```
只需将
"isHeaderFooterEnabled": False
添加到appstate
下面的更改中即可屏幕截图:注释了
chromeOpt.add_argument(' kiosk-printing')
行,只是为了在屏幕截图中显示取消选中的选项。您可以在下面的页面上找到有关chromium选项的详细信息
https://github.com/chromium/chromium/blob/eadef3f685cd9e96e94fcb9645b6838b6d0907a8/chrome/browser/resources/print_preview/data/model.js
相关问题 更多 >
编程相关推荐