您的位置:首页 > 编程语言 > Python开发

python selenium Frefox使 用代理访问网页

2014-12-12 14:05 288 查看
    因故需要代理访问网页,结果发现用selenium drive启动的firefox居然不会去读手动设置的代理,设置如下:

socks类型的代理

profile = webdriver.FirefoxProfile()

profile.set_preference('network.proxy.type', 1)   #默认值0,就是直接连接;1就是手工配置代理。

profile.set_preference('network.proxy.socks', ip)

profile.set_preference('network.proxy.socks_port', port)

profile.set_preference('network.proxy.ssl',ip)

profile.set_preference('network.proxy.ssl_port', port)

profile.update_preferences()

browser = webdriver.Firefox(profile)

browser.get("http://www.ip138.com")

如果是http类型的代理,则将proxy.socks改为proxy.http

=========================好记性不如烂笔头==========
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: