【发布时间】:2017-01-21 09:04:27
【问题描述】:
我已经尝试了人们尝试在堆栈溢出中配置火狐的所有最新和以前的方法,并且我一直在阅读所有documentation。 可能没有答案给出了许多人同意的为 Firefox 配置代理的明确方法。最近的一次是question 询问,指出他的初始方式成功配置了代理,但是当我尝试它时,我返回了 AttributeError。
from selenium import webdriver
IP = "###.###.###.###"
PORT = "####"
fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", IP)
fp.set_preference("network.proxy.http_port", int(PORT))
fp.update_preferences()
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('http://www.my-ip-address.net/')
我在 IP 和 PORT 上尝试了 int() 和 str() 的几种变体,但似乎没有任何效果。
我找不到任何似乎是最新的文档。如果有人可以向我推荐目前正在工作的东西,我将非常感激。
【问题讨论】:
-
代码在我的机器上完美运行,你是如何检查没有设置代理的?你能检查一下selenium打开的firefox吗?
-
它不会打开,所以我无法检查,而是收到此错误: Traceback(最近一次通话最后一次):文件“C:/Users/PC/Dropbox/Programing/YT Bot/ testfirefoxproxy.py”,第 11 行,在
driver = webdriver.Firefox(firefox_profile=fp) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium \webdriver\firefox\webdriver.py", line 126, in init if isinstance(firefox_profile, types.StringTypes): AttributeError: module 'types' has no attribute 'StringTypes' -
你运行的是不同版本的python吗?
-
我刚在python 2.7上试过,你用的是不同版本的firefox吗? @GaurangShah
-
你能用你得到的错误更新问题吗,你正在使用的 Firefox 和 Selenium 版本。
标签: python selenium firefox proxy python-3.6