我希望使用Selenium来运行一个无界面的Google Chrome实例,以从某些网站中挖掘数据,避免了UI开销。我从这里下载了ChromeDriver可执行文件,并将其复制到我的当前脚本目录。
该驱动程序似乎与Selenium一起正常工作,并能够自动浏览,但我似乎找不到无头选项。大多数在线使用Selenium和无头Chrome的示例大致如下:
该驱动程序似乎与Selenium一起正常工作,并能够自动浏览,但我似乎找不到无头选项。大多数在线使用Selenium和无头Chrome的示例大致如下:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'`
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"), chrome_options=chrome_options)
driver.get("http://www.duo.com")`
然而,当我使用命令chromedriver -h
检查Selenium WebDriver的可能参数时,我得到了以下内容:
D:\Jobs\scripts>chromedriver -h
Usage: chromedriver [OPTIONS]
Options
--port=PORT port to listen on
--adb-port=PORT adb server port
--log-path=FILE write server log to file instead of stderr, increases log level to INFO
--log-level=LEVEL set log level: ALL, DEBUG, INFO, WARNING, SEVERE, OFF
--verbose log verbosely (equivalent to --log-level=ALL)
--silent log nothing (equivalent to --log-level=OFF)
--append-log append log file instead of rewriting
--replayable (experimental) log verbosely and don't truncate long strings so that the log can be replayed.
--version print the version number and exit
--url-base base URL path prefix for commands, e.g. wd/url
--whitelisted-ips comma-separated whitelist of remote IP addresses which are allowed to connect to ChromeDriver
没有可用的--headless
选项。
从上面的链接获取的ChromeDriver是否允许无头浏览?