python-3.x - 如何在 AWS Cloud9 中安装 chromedriver?
问题描述
环境
aws ec2
ec2-user:~ $ which python
alias python='python36'
/usr/bin/python36
ec2-user:~ $ pip install chromedriver
Requirement already satisfied: chromedriver in ./.local/lib/python3.6/site-packages (2.24.1)
ec2-user:/usr/local/bin $ ls
chromedriver
问题
如何继续 chromeDriver.py 并获得想要的结果?
ec2-user:~/environment $ wget https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip
--2019-11-18 03:14:39-- https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip
Resolving chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)... 172.217.25.112, 2404:6800:4004:80b::2010
Connecting to chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)|172.217.25.112|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5527671 (5.3M) [application/zip]
Saving to: ‘chromedriver_linux64.zip’
chromedriver_linux64.zip 100%[=======================================>] 5.27M --.-KB/s in 0.1s
‘chromedriver_linux64.zip’ saved [5527671/5527671]
chromeDriver.py
from time import sleep
from selenium import webdriver
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
browser.get("https://www.google.com")
browser.save_screenshot("screen.png")
sleep(5)
browser.close()
这是一个结果。
ec2-user:~/environment $ python3 chromeDriver.py
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "chromeDriver.py", line 4, in <module>
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
File "/home/ec2-user/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/ec2-user/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
从路径 "$HOME:/.local/lib/python3.6/site-packages" 读取 selenium 是否正确?
解决方案
推荐阅读
- python - 来自 json 的响应即将到来
- javascript - React - 如果键存在,则过滤 JSON 数组
- flutter - 如何在颤振中添加入职屏幕?
- java - 如何在我的 Android 应用程序中运行 Linux 命令?
- r - r 替换低于矩阵中每列平均值的值
- python - Python中具有顺序的自相关矩阵
- firebase - 递归 Firebase Firestore 规则
- visual-studio - Docker 映像在 Windows/MVC 核心上构建的速度很慢
- javascript - 路由器推送后调用方法有什么负面影响吗?(Vue.js)
- git - 如何在复杂的 git rebase 中恢复已删除的文件?