小编Tra*_*tar的帖子

如何禁用页眉和页脚 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()')```
Run Code Online (Sandbox Code Playgroud)

python selenium

2
推荐指数
1
解决办法
3207
查看次数

标签 统计

python ×1

selenium ×1