gpt4 book ai didi

python - 如何在 python 中使用 selenium 运行 headless chrome 和代理?

转载 作者:行者123 更新时间:2023-12-01 09:12:29 33 4
gpt4 key购买 nike

我的python脚本在selenium中有 headless (headless)chrome并且功能正常,但是如果可能的话,我如何也可以使用代理?如何将代理主机端口传递到我的 headless (headless) Chrome 浏览器?

options = webdriver.ChromeOptions()  
options.add_argument('headless')
browser = webdriver.Chrome(chrome_options=options)

如何将代理主机端口与 selenium 和主要是 headless (headless) Chrome 一起使用?谢谢!

最佳答案

类似这样的事情:

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType


options = webdriver.ChromeOptions()
options.add_argument('headless')
desired_caps = options.to_capabilities()

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = "ip_addr:port"
prox.socks_proxy = "ip_addr:port"
prox.ssl_proxy = "ip_addr:port"
prox.add_to_capabilities(desired_caps)


browser = webdriver.Chrome(desired_capabilities=desired_caps)

关于python - 如何在 python 中使用 selenium 运行 headless chrome 和代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51539818/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com