python - 如何在 python webdriver 中为 chrome 设置代理?

标签 python google-chrome proxy webdriver

我正在使用此代码:

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy.server.address")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)

在 python webdriver 中为 FF 设置代理。这适用于FF。如何在 Chrome 中设置这样的代理?我找到了 exmaple但不是很有帮助。当我运行脚本时没有任何反应(Chrome 浏览器未启动)。

最佳答案

from selenium import webdriver

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

chrome = webdriver.Chrome(options=chrome_options)
chrome.get("http://whatismyipaddress.com")

关于python - 如何在 python webdriver 中为 chrome 设置代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11450158/

相关文章:

api - 使用 tfl 数据 api - 教程?

python - Opencv iOS安装

python - 使用python将文件下载/上传到远程windows服务器

javascript - 提升行为在 chrome 48 和 49 之间发生了变化?

javascript - 使用ip地址和localhost在机器上打开网站的区别?

请求库的 Python 代理错误

python - 为什么 Tor 无法访问本地主机页面

Python矩阵(列表列表)到字典

java - 在python中实例化一个java类并将其发送回java

javascript - 将 Chrome 更新到版本 60 后布局过程变慢