我需要在Python中通过代理使用Selenium。我的私有代理类型是:user:password:ip:port
。下面的代码可以工作,但是没有user
和password
选项。有人能更新这个代码吗?谢谢。你知道吗
from selenium import webdriver
import time
"Define Both ProxyHost and ProxyPort as String"
ProxyHost = "ip"
ProxyPort = "port"
def ChangeProxy(ProxyHost ,ProxyPort):
"Define Firefox Profile with you ProxyHost and ProxyPort"
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", ProxyHost )
profile.set_preference("network.proxy.http_port", int(ProxyPort))
profile.update_preferences()
return webdriver.Firefox(firefox_profile=profile)
def FixProxy():
"Reset Firefox Profile"
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 0)
return webdriver.Firefox(firefox_profile=profile)
driver = ChangeProxy(ProxyHost ,ProxyPort)
driver.get("http://whatismyipaddress.com")
time.sleep(5)
driver = FixProxy()
driver.get("http://whatismyipaddress.com")
定义属性:
然后将这些添加到您的首选项中:
另一种说法:
相关问题 更多 >
编程相关推荐