Chrome由自动化测试软件控制;“不安全”;数据:,Python

Chrome由自动化测试软件控制;“不安全”;数据:,Python,python,google-chrome,selenium,Python,Google Chrome,Selenium,我正在使用python中的selenium库打开google chrome并自动访问google.com,这就是我的脚本目前的样子 import os from selenium import webdriver from selenium.webdriver.chrome.options import Options chromedriver = "/usr/bin/chromedriver" os.environ["webdriver.chrome.driver"] = chromed

我正在使用python中的selenium库打开google chrome并自动访问google.com,这就是我的脚本目前的样子

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


chromedriver = "/usr/bin/chromedriver"

os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = webdriver.ChromeOptions()
chrome_options.accept_untrusted_certs = True
chrome_options.assume_untrusted_cert_issuer = True
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--allow-http-screen-capture")
chrome_options.add_argument("--disable-impl-side-painting")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--disable-seccomp-filter-sandbox")
chrome_options.add_options("--enable-automation")
chrome_options.add_options("--disable-infobar")
driver = webdriver.Chrome(chromedriver, chrome_options=chrome_options)

driver.get("http://google.com/")
“我的浏览器”选项卡从不显示google.com,它只是挂在那里

我的chromedriver版本是:chromedriver 2.39 我的Google Chrome版本是:Google Chrome 67.0

在执行Ctrl+c之后,我得到这个输出

Traceback (most recent call last):
File "auto-run.py", line 16, in <module>
driver = webdriver.Chrome(chrome_path, chrome_options=chrome_options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 496, in _request
resp = self._conn.getresponse()
File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
回溯(最近一次呼叫最后一次):
文件“auto run.py”,第16行,在
driver=webdriver.Chrome(Chrome\u路径,Chrome\u选项=Chrome\u选项)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/chrome/webdriver.py”,第75行,在__
期望的_能力=期望的_能力)
文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”,第156行,在__
启动会话(功能、浏览器配置文件)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/webdriver.py”,第245行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”,第312行,在execute中
响应=self.command\u executor.execute(driver\u command,params)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/remote_connection.py”,第472行,在execute中
返回self.\u请求(命令信息[0],url,正文=数据)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/remote\u connection.py”,第496行,在请求中
resp=self.\u conn.getresponse()
文件“/usr/lib/python3.6/http/client.py”,第1331行,在getresponse中
response.begin()
文件“/usr/lib/python3.6/http/client.py”,第297行,在begin中
版本、状态、原因=self.\u读取\u状态()
文件“/usr/lib/python3.6/http/client.py”,第258行,处于读取状态
line=str(self.fp.readline(_MAXLINE+1),“iso-8859-1”)
readinto中的文件“/usr/lib/python3.6/socket.py”,第586行
返回自我。将袜子重新放入(b)
键盘中断

如果您能帮我解释一下为什么——启用自动化不起作用,我们将不胜感激

您缺少chromedriver的完整路径,包括.exe。使用类似的或完全合格的chromedriver

webdriver.Chrome(executable_path='drivers\chromedriver.exe')

我以这种方式修改了您的脚本,并成功地执行了它

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_path  = '/Users/zac/Desktop/chromedriver_mac64/chromedriver'
#this would be the path to the chromedriver exe on your system

chrome_options = webdriver.ChromeOptions()
chrome_options.accept_untrusted_certs = True
chrome_options.assume_untrusted_cert_issuer = True
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--allow-http-screen-capture")
chrome_options.add_argument("--disable-impl-side-painting")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--disable-seccomp-filter-sandbox")
driver = webdriver.Chrome(chrome_path, chrome_options=chrome_options)

driver.get("http://google.com/")

另外,您需要使用
添加参数
而不是
添加选项
来设置
--启用自动化
标志

是否引发了任何错误?没有引发错误,只是一个空白网页我在Linux机器上,不是windowsok,chrome驱动程序的路径在哪里。我的意思是它的位置我复制并粘贴了你的脚本,修改了我到chrome的路径,并添加了chrome选项。添加了参数(“--enable automation”),但仍然没有成功:\n不要将它保存在
/usr/bin
文件夹中。更改到您具有可执行权限的位置。最好的办法是把它放在你的下载文件夹中,放在一个名为drivers的新文件夹下。。像
/usr/your_name/Downloads/driver/chromedriver
Done.,但仍然没有luckAlso,进入保存chromedriver的文件夹并执行
chmod+x chromedriver.exe
仍然没有运气不幸的是,在执行ctrl+c之后,我编辑了我的问题并包含了堆栈跟踪