我正在使用 python3 在 Linux 和 unDetected_chrome 上运行 selenium 自动化脚本。
我也在使用代理。
当我只运行一个实例时,它工作正常并完成工作,但是启动第二个实例时我收到此错误:
2024-04-30 00:09:28 - ERROR - HTTPConnectionPool(host='localhost',
port=44073): Max retries exceeded with url:
/session/2488e939aa54121cb42b165948495489/actions (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7debd7c86fb0>: Failed to establish a new connection: [Errno 111]
Connection refused'))
尽管每个驱动程序的代理都会发生变化。
我已经尝试了各种我能想到的解决方案。
此解决方案使用 SeleniumBase UC 模式 而不是
undetected-chromedriver
来隐秘地同时启动多个 Web 浏览器:(pip install seleniumbase
)
import sys
from concurrent.futures import ThreadPoolExecutor
from seleniumbase import Driver
sys.argv.append("-n") # Activate SB thread-locking as needed
def launch_driver(url):
driver = Driver(uc=True)
try:
driver.uc_open_with_reconnect(url, 4)
driver.sleep(2)
finally:
driver.quit()
urls = ['https://gitlab.com/users/sign_in' for i in range(3)]
with ThreadPoolExecutor(max_workers=len(urls)) as executor:
for url in urls:
executor.submit(launch_driver, url)
请务必将示例 URL(使用机器人检测软件)替换为您想要的 URL。