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

How to Import Selenium in Google Cloud Platform Virtual Machine?

我已经在 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 选项,它将起作用:

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

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