|
22 | 22 | from bs4 import BeautifulSoup |
23 | 23 | from PySide6.QtCore import * |
24 | 24 | from PySide6.QtGui import * |
| 25 | +from selenium.webdriver import DesiredCapabilities |
| 26 | +from selenium.webdriver.common.proxy import Proxy |
| 27 | +from selenium.webdriver.common.proxy import ProxyType |
25 | 28 | from tls_client import Session as TlsSession |
26 | 29 | from undetected_chromedriver import Chrome |
27 | 30 | from undetected_chromedriver import ChromeOptions |
@@ -365,6 +368,22 @@ def set_user_agent(message: dict[str, Any]) -> None: |
365 | 368 | self.updateUserAgent.emit(ua) |
366 | 369 |
|
367 | 370 | options = ChromeOptions() |
| 371 | + if self.session.proxies: |
| 372 | + proxy = Proxy() |
| 373 | + proxy.proxy_type = ProxyType.MANUAL |
| 374 | + if http := self.session.proxies.get('http'): |
| 375 | + if (match := CG_PROXY_PATTERN.match(http)) is not None: |
| 376 | + config: dict[str, str] = match.groupdict() |
| 377 | + proxy.http_proxy = f'{config["host"]}:{config["port"]}' |
| 378 | + if socks := self.session.proxies.get('socks5'): |
| 379 | + if (match := CG_PROXY_PATTERN.match(socks)) is not None: |
| 380 | + config: dict[str, str] = match.groupdict() |
| 381 | + proxy.socks_proxy = f'{config["host"]}:{config["port"]}' |
| 382 | + proxy.socks_username = config['username'] |
| 383 | + proxy.socks_password = config['password'] |
| 384 | + proxy.add_to_capabilities(DesiredCapabilities.CHROME) |
| 385 | + options.proxy = proxy |
| 386 | + |
368 | 387 | for argument in ( |
369 | 388 | '--disable-extensions', '--disable-application-cache', |
370 | 389 | '--disable-gpu', '--no-sandbox', |
|
0 commit comments