简体   繁体   English

Chrome 浏览器 Headless 问题:某些特定页面未在 Headless 模式下呈现

[英]Chrome Browser Headless problem : Some specific pages are not rendering in Headless mode

I am trying to automate a process using selenium and chrome browser in Python. My browser works correctly for most pages but is unable to render a few pages including chrome://version/ .我正在尝试使用 selenium 和 Python 中的 chrome 浏览器自动执行一个过程。我的浏览器对大多数页面都能正常工作,但无法呈现包括chrome://version/在内的一些页面。 For general automation(without headless) it returns the page and page source correctly, whereas for headless browsing it returns a blank page with page source as below对于一般自动化(没有无头),它会正确返回页面和页面源,而对于无头浏览,它会返回一个空白页面,页面源如下

<html><head></head><body></body></html>

I have tried chrome in the different operating system including OpenSUSE, fedora, and Windows. I have tried many things like: Removing all the initial arguments, Used the browser with headless off.我在不同的操作系统中尝试过 chrome,包括 OpenSUSE、fedora 和 Windows。我尝试了很多事情,例如:删除所有初始的 arguments,使用无头关闭的浏览器。 For Reference: If I run this code供参考:如果我运行此代码

from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions
options = ChromeOptions()
# to remove all arguments
options.add_experimental_option( 'excludeSwitches', ['disable-hang-monitor', 'disable-prompt-on-repost', 'disable-background-networking', 'disable-sync', 'disable-translate', 'disable-web-resources', 'disable-client-side-phishing-detection', 'disable-component-update', 'disable-default-apps', 'disable-zero-browsers-open-for-tests', '--enable-automation', '--use-mock-keychain', '--user-data-dir', '--enable-blink-features', '--disable-popup-blocking', '--enable-logging --force-fieldtrials=SiteIsolationExtensions/Control', '--enable-logging', '--force-fieldtrials', '--ignore-certificate-errors', '--load-extension', '--log-level', '--no-first-run','--password-store','--remote-debugging-port','--test-type'
]) 
options.add_argument("--headless")
options.add_argument("--no-sandbox")
browser = Chrome(executable_path=driver_path,options=options)
browser.get("chrome://version")
print(browser.page_source)

It returns the same blank page for headless它为无头返回相同的空白页

<html><head></head><body></body></html>

If the chrome is operated without headless option it will work completely fine.如果 chrome 在没有无头选项的情况下运行,它将完全正常工作。

<!doctype html>
<!--
about:version template page
-->
<html id="t" dir="ltr" lang="en">
  <head>
    <meta charset="utf-8">
    <title>About Version</title>
    <link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
    <link rel="stylesheet" href="chrome://version/about_version.css">
......................

You might try using the argument:您可以尝试使用参数:

options.add_argument("--headless=chrome")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM