from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.http', 'proxy_url')
profile.set_preference('network.proxy.http_port', 3128)
profile.set_preference('network.proxy.ssl', 'proxy_url')
profile.set_preference('network.proxy.ssl_port', 3128)
profile.update_preferences()
driver = webdriver.Firefox(profile)

这些坑分别是:

有些地方只告诉你配置network.proxy.http和network.proxy.http_port。但是如果不设置network.proxy.type,一切都是浮云。这个配置是个整数,默认是0,就是直接连接;1就是手工配置代理。
profile.set_preference(‘network.proxy.type’, 1)

那个端口号3128是整数
profile.set_preference(‘network.proxy.http’, ‘proxy_url’)
profile.set_preference(‘network.proxy.http_port’, 3128)

如果有些资源是https的,是需要另外配置network.proxy.ssl和network.proxy.ssl_port的。例如facebook的图片。。。

set完以后,是需要update_preferences的。。。
profile.update_preferences()

最后贴一个完整的Firefox配置参数表:http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries

如果发现自己的配置好像没有生效,那么在webdriver启动的Firefox里面输入about:config。然后对着上面那个配置参数表来看。总会发现掉哪个坑的。

转自http://magustest.com/2011/09/23/proxy-config-of-firefox-driver/

selenium firefox设置代理的更多相关文章

  1. python爬虫——selenium+firefox使用代理

    本文中的知识点: python selenium库安装 firefox geckodriver的下载与安装 selenium+firefox使用代理 进阶学习 搭建开发环境: selenium库 fi ...

  2. Selenium/HtmlUnit设置代理获取JS生成的网页

    通常我们使用Java提供的HttpURLConnection或者Apache的HttpClient获取的网页源代码都是直观可见的,其代码的内容和通过浏览器右键网页->点击查看网页源代码的内容一致 ...

  3. selenium phantomjs 设置代理ip方法

    最近遇到phantomjs动态更换ip的功能,在知乎上看到一篇不错的文章,顺手记下来以备后用 phantomjs selenium 如何动态修改代理? 可以这样做(Python代码): # 不使用代理 ...

  4. CentOS7 设置代理

    大多数公司的网络都使用局域网加代理上网,也就是说上外网必须使用公司指定的代理服务器,这有几个好处: 1. 首先代理可以一定程度提高浏览速度,因为可以将更多的网页缓存在代理服务器上,需要的时候直接拿就很 ...

  5. selenium设置代理,基于chrome浏览器

    工作中遇到需要对项目中使用的selenium设置代理,跟大家分享一下. 1.下载chromeDriver:http://chromedriver.storage.googleapis.com/inde ...

  6. CentOS7设置系统/yum以及firefox web代理上网

    一.系统全局的代理设置: 用vi/vim编辑器打开/etc/profile,追加如下内容: http_proxy=http://192.168.78.124:8080 ftp_proxy=http:/ ...

  7. python3 selenium模块Chrome设置代理ip的实现

    python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...

  8. selenium设置Chrome浏览器不出现通知,设置代理IP

    from selenium import webdriver PROXY = "" chrome_options = webdriver.ChromeOptions() prefs ...

  9. Python selenium + Firefox启动浏览器

    Python selenium 的运用 from selenium import webdriver # from selenium.webdriver.firefox.firefox_profile ...

随机推荐

  1. VS2013下配置OpenCV 3.0.0 &&& VS2013下配置Opencv2.4.9

    最近做图像需要用到Matlab和OpenCV,一些东西真的是要深入的研究进去才会有所发现,但Matlab和C++都不是我擅长的语言,所以要很加油很加油才行啊!! 步入正题. 1.  环境:Win7 6 ...

  2. [poj] 1235 Farm Tour || 最小费用最大流

    原题 费用流板子题. 费用流与最大流的区别就是把bfs改为spfa,dfs时把按deep搜索改成按最短路搜索即可 #include<cstdio> #include<queue> ...

  3. 从Jetty、Tomcat和Mina中提炼NIO构架网络服务器的经典模式

    如何正确使用NIO来构架网络服务器一直是最近思考的一个问题,于是乎分析了一下Jetty.Tomcat和Mina有关NIO的源码,发现大伙都基于类似的方式,我感觉这应该算是NIO构架网络服务器的经典模式 ...

  4. #!/bin/sh简介

    第一次学shell编程,看的文章中说shell程序必须以"#!/bin/sh"开始,也就认为是这样了,虽然知道在shell中以"#"开始的语句都是注释,但也从没 ...

  5. Jquery CheckBox 选中和非选中

    if($("input[name='is_pay']").prop('checked')) { $("input[name='is_pay']").prop(' ...

  6. iOSCompile

    https://wiki.videolan.org/iOSCompile iOSCompile Contents [hide] 1 Development environment 2 Get the ...

  7. How do I list all fields of an object in Objective-C?

    http://stackoverflow.com/questions/1213901/how-do-i-list-all-fields-of-an-object-in-objective-c As m ...

  8. Linux安转jdk

    1. 创建目录 > mkdir  /opt/java > cd /opt/java 2. 下载jdk压缩包到上述目录 jdk-8u162-linux-x64.tar.gz 3. 解压缩.建 ...

  9. java获取当前类名和方法名

    Description Below I present you two different ways to get the current Class: Using Thread Using getC ...

  10. Selenium2+python自动化12-操作元素(键盘和鼠标事件)【转载】

    前言 在前面的几篇中重点介绍了一些元素的到位方法,到位到元素后,接下来就是需要操作元素了.本篇总结了web页面常用的一些操作元素方法,可以统称为行为事件 有些web界面的选项菜单需要鼠标悬停在某个元素 ...