python selenuim使用代理的方式

时间:2022-02-06 13:46:51

一、FireFox浏览器

  

 myProxy = "60.195.250.55:80"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': ''
})
driver = webdriver.Firefox(proxy=proxy)

二、Phantomjs

service_args = [
'--proxy=60.195.250.55:80',
'--proxy-type=socks5',
]
driver = webdriver.PhantomJS(executable_path='D:\phantomjs-2.1.1-windows\phantomjs.exe',service_args=service_args)

无论如何,记得先确保代理服务器能用,否则都是徒劳