![](/img/trans.png)
[英]Unable to run chromedriver using Python & selenium in cloud9 & aws
[英]Unable to run chromedriver using selenium in Python in aws cloud9
在将seelenium,chrome和chromedriver安装到AWS cloud9之后,我尝试执行chromedriver。 但是发生了PATH错误。
我检查了chromedriver路径是否正确。 而且我不知道为什么会发生此错误。
aws:~/environment/seleniumTest $ ll /home/ec2-user/environment/seleniumTest/chromedriver
-rwxr-xr-x 1 ec2-user ec2-user 8496784 Sep 13 2018 /home/ec2-user/environment/seleniumTest/chromedriver
是否有解决此问题的解决方案?
我的步骤如下
1.安装selenium pip安装selenium -t ./
2.安装chrome curl https://intoli.com/install-google-chrome.sh | 重击
3.下载chromedriver curl -SL https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip > chromedriver.zip解压缩chromedriver.zip
4,执行以下Python代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def lambda_handler(event, context):
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome('/home/ec2-use/environment/seleniumTest/chromedriver', chrome_options=options)
return(0)
我收到“'chromedriver'可执行文件需要在PATH中”错误。
Response
{
"errorMessage": "Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home\n",
"errorType": "WebDriverException",
"stackTrace": [
[
"/var/task/seleniumTest/lambda_function.py",
9,
"lambda_handler",
"driver = webdriver.Chrome('/home/ec2-use/environment/seleniumTest/chromedriver', chrome_options=options)"
],
[
"/var/task/selenium/webdriver/chrome/webdriver.py",
73,
"__init__",
"self.service.start()"
],
[
"/var/task/selenium/webdriver/common/service.py",
83,
"start",
"os.path.basename(self.path), self.start_error_message)"
]
]
}
Function Logs
Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
: WebDriverException
Traceback (most recent call last):
File "/var/task/seleniumTest/lambda_function.py", line 9, in lambda_handler
driver = webdriver.Chrome('/home/ec2-use/environment/seleniumTest/chromedriver', chrome_options=options)
File "/var/task/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/var/task/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我不确定您是否为Chromedriver指定了正确的execute_path,我认为以下方法应该有效:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def lambda_handler(event, context):
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(executable_path='/home/ec2-user/environment/seleniumTest/chromedriver', chrome_options=options)
return(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.