from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *
import time
# for fresh FF profile
#profile = webdriver.FirefoxProfile()
profile_path="/path/to/custom/profile/"
profile = webdriver.FirefoxProfile(profile_path)
# set FF preference to socks proxy
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "10.10.10.1")
profile.set_preference("network.proxy.socks_port", 8999)
profile.set_preference("network.proxy.socks_version", 5)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("http://whatismyip.com")
print driver.page_source
# sleep if want to show in gui mode. we do print it in cmd
time.sleep(25)
driver.close()
driver.quit()
在您的情况下,我认为,应该将port用作int而不是string。详见下文
首先让我们了解FF(或与Selenium一起使用的webdriver)是如何设置SOCKS代理的。
对于Firefox,在URL框中执行about:config。
您可以在FF profile director的prefs.js中看到相同的内容,如下所示:
请注意,network.proxy.socks是string,应该只设置为string。network.proxy.socks_port也必须是int
使用selenium python模块设置时:
请检查是否支持给定的首选项,并在FF about:config列表中显示。
查看用户如何使用socks_端口。。。。在下面的例子中
using-selenium-for-web-based-hostname-enumeration 和gist.github.com
相关问题 更多 >
编程相关推荐