如何在python webdriver中为phantomjs/ghostdriver设置代理? [英] How do I set a proxy for phantomjs/ghostdriver in python webdriver?

查看:102
本文介绍了如何在python webdriver中为phantomjs/ghostdriver设置代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何通过HTTP代理路由请求.

I'm trying to figure out how to route my requests through an HTTP proxy.

我正在像这样初始化webdriver:

I'm initializing webdriver like this:

user_agent = 'my user agent 1.0'
DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = user_agent
driver = webdriver.PhantomJS()

我已经浏览了文档和源代码,似乎找不到找到通过Webdriver通过phantomjs使用代理服务器的方法.

I've gone through the docs and the source and can't seem to find a way to use a proxy server with phantomjs for through webdriver.

有什么建议吗?

推荐答案

下面是如何在Python中设置PhantomJs代理的示例.您可以更改代理类型:socks5/http.

Below is the example of how to set proxy for PhantomJs in Python. You may change proxy type: socks5/http.

service_args = [
    '--proxy=127.0.0.1:9999',
    '--proxy-type=socks5',
    ]
browser = webdriver.PhantomJS('../path_to/phantomjs',service_args=service_args)

这篇关于如何在python webdriver中为phantomjs/ghostdriver设置代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆