爬虫萌新一枚,最近在用selenium作动态页面的处理,但是时间久了会遇到被禁止访问的情况,在网上找了一些设置selenium代理的资料,每个都尝试了,但是还是不行,网页都打不开。
方法一:
options = webdriver.FirefoxOptions()
options.add_argument('--proxy-server=xxxx:xxxx')
方法二:
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': 'https://58.218.92.89:8272'
}
)
driver = webdriver.Firefox(firefox_options=options, proxy=proxy)
方法三:
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.http', '58.218.92.159')
profile.set_preference('network.proxy.http_port', 5057) # int
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
方法四:
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': '58.218.200.253:5762' # 代理ip和端口
}
)
# 新建一个“期望技能”,哈哈
desired\_capabilities = DesiredCapabilities.CHROME.copy()
# 把代理ip加入到技能中
proxy.add_to_capabilities(desired_capabilities)
driver = webdriver.Chrome(desired_capabilities=desired_capabilities)
以上方法都有实践和测试过,但是都打不开网页,请路过的大佬指点一下,如何设置selenium的代理ip
测了一下这样是可以的
打开后是这样:
