selenium ChromeDriver-防火墙后的自动安装程序

insrf1ej  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(142)

有没有办法在防火墙后使用ChromeDriver-自动安装程序?
或者,当你在防火墙后面时,有没有其他更合适的解决方案来维护ChromeDriver?

jv4diomz

jv4diomz1#

以下是我如何使用WebDriver管理器来解决我的问题:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.download_manager import WDMDownloadManager
from webdriver_manager.core.http import HttpClient
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from requests import Response
import urllib3
import requests
import os
import time
os.environ['WDM_SSL_VERIFY'] = '0'
capabilities = webdriver.DesiredCapabilities.CHROME
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

PROXY = "http:// *proxy adress*"
opt = webdriver.ChromeOptions()
opt.add_argument('--proxy-server=%s' % PROXY)
opt.add_argument("ignore-certificate-errors")
opt.add_argument(f'user-data-dir=C:\\Users\\ *Location of the Chrome profile*')

class CustomHttpClient(HttpClient):
    def get(self, url, params=None) -> Response:
        proxies={'http': 'http:// *proxy adress*',
         'https': 'http:// *proxy adress*',
         }
        return requests.get(url, params,proxies=proxies,verify=False)

http_client = CustomHttpClient()
download_manager = WDMDownloadManager(http_client)

driver = webdriver.Chrome(service=Service(ChromeDriverManager(download_manager=download_manager).install()),options=opt)

相关问题