Python Selenium Firefox 代理设置


Python Selenium Firefox 代理设置

方案一(失败)

Python 全选
 from selenium import webdriver
from selenium.webdriver.common.proxy import *

use_proxy=agent_IP+':'+str(agent_Port)

_proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': use_proxy,
    'ftpProxy': use_proxy,
    'sslProxy': use_proxy,
    'noProxy': None, # set this value as desired
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
    })
browser = webdriver.Firefox(proxy=_proxy)
browser.get('https://www.google.com')

方案二(失败)

Python 全选
from selenium import webdriver

profile = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.share_proxy_settings", True)
profile.set_preference("network.http.use-cache", False)
profile.set_preference("network.proxy.http", agent_IP)
profile.set_preference("network.proxy.http_port", int(agent_Port))
profile.set_preference('network.proxy.ssl_port', int(agent_Port))
profile.set_preference('network.proxy.ssl', agent_IP)
profile.set_preference("general.useragent.override","whater_useragent")
profile.update_preferences() 
browser = webdriver.Firefox(firefox_profile=profile)
browser.get('https://www.google.com')

方案三(有效)

Python 全选
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

PROXY = "58.216.202.149:8118"

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": PROXY,
    "ftpProxy": PROXY,
    "sslProxy": PROXY
}

driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver.get(url)

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
管理员
上一篇:记一次数据库查询优化记录
下一篇:Python Selenium使用火狐浏览器驱动
评论列表

发表评论

评论内容
昵称:
关联文章

Python Selenium Firefox 代理设置
Python Selenium使用火狐浏览器驱动
Python Selenium ChromeDriver 规避检测
Python使用selenium+chrome配置指南
Python使用selenium+chrome进行抓包
使用 mitmproxy + python 做拦截代理
Python Selenium 爬虫如何隐藏Headles-Chrome不被检测出来 避免检测
C#爬虫:使用Selenium,Selenium配置指南
selenium爬虫被检测到 该如何破
Python Selenium 前端如何检测Chrome-Headless不被爬虫虐
Python Selenium 抓包注入记录
Python Windows服务
VScode配置Python开发环境
Python修改cmd窗口标题
.NET Core 实现动态代理做AOP(面向切面编程)
Python安装
python抓包 ChromeDriver下载地址
Python pyinstaller 打包参数说明
YARP+AgileConfig 5分钟实现一个支持配置热更新的代理网关
Devexpress XtraTabControl设置

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码