![](/img/trans.png)
[英]is it possible to get the selenium headless chrome XHR response when using Python 3
[英]Is it possible to prevent the headless Chrome window get up when running it?
在我的 Mac 上,我使用以下 selenium 代码在无头 Chrome 中搜索 Python 关键字。
from selenium import webdriver
wd = webdriver.Chrome(r"/opt/webdrivers/chromedriver")
wd.implicitly_wait(5)
wd.get("https://www.google.com")
element = wd.find_element_by_id('kw')
element.send_keys('Python\n')
element = wd.find_element_by_class_name('c-abstract')
print(element.text)
但是,Chrome 会自动打开一个窗口。
我对无头浏览器的理解现在将打开一个窗口。 尽管如此,有没有可能抑制GUI起来,让它静默运行?
我不知道headless chrome
但您可以通过以下选项在无头模式下运行 chrome
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
wd = webdriver.Chrome(r"/opt/webdrivers/chromedriver")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.