如何在Google云平台虚拟机中导入Selenium?

2024-03-28 15:04:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在谷歌云平台上创建了一个虚拟机。VM确实允许我运行Python代码,但它不允许我导入selenium

我看过几个视频,他们使用docker导入硒,但对我来说不起作用

有人知道如何将selenium导入您的Google云平台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

正如您所看到的,它说我没有路径,但另一方面,我已经在代码中这样做了


Tags: path代码inpyhomelibseleniumline
1条回答
网友
1楼 · 发布于 2024-03-28 15:04:53

如果您使用此selenium选项,它将起作用:

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

options = Options()
options.add_argument(' headless')

相关问题 更多 >