在EC2中安装chrome浏览器headless Selenium Python

2024-04-27 00:48:14 发布

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

我尝试在我的EC2实例上以headless模式运行Python Selenium会话。 我很难尝试在无头模式下使用Chrome。在

import os
import json
import time
from selenium import webdriver
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
options.add_argument("window-size=1366,768")

if options.headless:
    options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                         'Chrome/71 Safari/537.36')

BASE_DIR = os.path.dirname(os.path.abspath('__file__'))

driver = webdriver.Chrome(executable_path='/home/ec2-user/certs/chromedriver.exe', chrome_options=options)

我收到以下错误,但我不明白:

WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

你能告诉我解决这个问题的步骤吗?在

非常感谢。在


Tags: pathfromimportsupportosselenium模式common