selenium中Firefox设置代理(python)

selenium中Firefox设置代理(python)

参考:

https://zhuanlan.zhihu.com/p/39281522

https://passerbyy.iteye.com/blog/1286292

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile


## 第一步:创建一个FirefoxProfile实例
profile = FirefoxProfile()
## 第二步:开启“手动设置代理”
profile.set_preference('network.proxy.type', 1)
## 第三步:设置代理IP
profile.set_preference('network.proxy.http', '112.87.71.4')
## 第四步:设置代理端口,注意端口是int类型,不是字符串
profile.set_preference('network.proxy.http_port', 9999)
## 第五步:设置htpps协议也使用该代理
profile.set_preference('network.proxy.ssl', proxy_host)
profile.set_preference('network.proxy.ssl_port', proxy_port)

driver = webdriver.Firefox(profile)
driver.get('http://httpbin.org/get')

如果是收费代理,需要进行认证,此时单单传入host和port需要填写认证表单
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/eighttoes/article/details/86762222