因故需要代理访问网页,结果发现用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
=========================好记性不如烂笔头==========