我有一个使用Selenium/Chromedriver的应用程序,可以无头运行chrome。在我的本地机器上,它工作得很好。当试图在Ubuntu16.04的AWS-EC2实例上运行时,我每次都会得到一个错误;
ConnectionResetError: [Errno 104] Connection reset by peer安全组的出站规则允许所有端口上的所有通信量。
对等错误重置意味着我被服务器锁定,但我无法解释为什么我仍然可以在本地运行?对错误的来源有任何见解吗?
设置:
注意:使用来自同一服务器的Robobrowser完成,没有问题。
SteveJ
发布于 2018-06-19 19:22:21
下面的代码我取得了轻微的成功。请注意,它仍然非常挑剔..。看起来,在一个驱动程序会话之后,服务器停止了连接(我们看到104个错误)。
首先,确保下载适当的色驱动器。遵循以下要点:https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5
接下来,运行/usr/local/bin/chromedriver启动chomedriver。你应该看到:
启动ChromeDriver 2.40.565383
接下来,打开一个新的Putty控制台并设置您的WebDriver。我最喜欢的做法是:
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.webdriver import WebDriver
chrome_options = Options()
chromes_options.set_headless()
driver=WebDriver('/usr/local/bin/chromedriver',chrome_options=chrome_options)
## Note the above 'executable path' of the chromedriver is based on the above gist
driver.get('https://google.com')希望这是有用的。
其他故障排除可能包括:
++确保您为google分配了一个公钥(如下图所示:https://krbnite.github.io/Driving-Headless-Chrome-with-Selenium-on-AWS-EC2/#comment-3951560468)
++将下列标志传递给您的铬选项:“--无沙箱”&“禁用-开发-shm-使用”
++确保在运行脚本后"sudo killall -9 chrome“,以确保chromedriver实例已经消失!
https://stackoverflow.com/questions/48133720
复制相似问题