小编Aam*_*nIs的帖子

将 Chromedriver 用于无头浏览器时出现“权限策略标头错误”

在 Selenium 上,我使用的是 chromedriver 版本 89 和我的 chrome 浏览器版本 89.0。也。当我在无头浏览器上运行代码时,出现错误;将 chrome 转换为无头浏览器以测试结果。这是我的脚本-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from shutil import which 

chrome_options = Options()
chrome_options.add_argument("--headless")

chrome_path = which("chromedriver")

driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.get("https://duckduckgo.com/")

search_input = driver.find_element_by_id("search_form_input_homepage")
search_input.send_keys("My User Agent")

search_input.send_keys(Keys.ENTER)
Run Code Online (Sandbox Code Playgroud)

这是 VSCODE 终端输出,

DevTools listening on ws://127.0.0.1:57195/devtools/browser/7464cfb0-5b3c-497d-a768-6eae3bb5b59b
[0408/112137.788:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)
[0408/112138.552:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)
[0408/112139.176:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized …
Run Code Online (Sandbox Code Playgroud)

selenium

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

标签 统计

selenium ×1