【发布时间】:2020-11-08 22:25:09
【问题描述】:
我在 Google Cloud Platform 中创建了一个虚拟机。 VM 允许我运行 Python 代码,但不允许我导入 selenium。
我看过几个视频,他们使用 docker 导入 selenium,但对我没有用。
有人知道如何将 selenium 导入您的 Google Cloud Platform VM 吗?
当我运行这段代码时:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:/home/juan_vecinodeharo/chromedriver.exe")
driver.get("http://www.python.org")
它给了我这个错误:
Traceback (most recent call last):
File "/home/juan_vecinodeharo/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'C:/home/juan_vecinodeharo/chromedriver.exe': 'C:/home/juan_vecinodeharo/chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "hello world.py", line 3, in <module>
driver = webdriver.Chrome(executable_path="C:/home/juan_vecinodeharo/chromedriver.exe")
File "/home/juan_vecinodeharo/.local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/juan_vecinodeharo/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
如您所见,它说我没有路径,但另一方面我已经在代码中完成了。
【问题讨论】:
-
为了使用 selenium,您需要同时安装 1) 与 VM 操作系统兼容的 webdriver 二进制文件和 2) Python 库。在这个链接上很好地覆盖了这个话题:selenium.dev/documentation/en/webdriver/driver_requirements
-
您收到的错误消息是什么,到目前为止您尝试过什么?您是否在设置中使用了任何指南?请提供更详细的故障排除说明。
-
@AlexG 我已经完成了“pip install -U selenium”,并且我的 selenium 已导入到 './.local/lib/python3.7/site-packages' 但现在我找不到我的网络驱动程序路径。我也不知道是否需要在我的 Debian VM 中显式安装 chrome。我是 GCP 的新手。
标签: python selenium google-cloud-platform virtual-machine