row*_*asc 2 python selenium webdriver socks
我习惯像这样设置http端口:
profile.set_preference("network.proxy.http_port", "PORTNUMBER")
Run Code Online (Sandbox Code Playgroud)
这很有效.但现在我需要连接socks代理并设置端口,它不起作用
profile.set_preference("network.proxy.socks_port", "PORTNUMBER")
Run Code Online (Sandbox Code Playgroud)
我在文档中找不到引用,这就是我在这里问的原因.有任何想法吗 ?有没有更好的方法呢?
谢谢
在下面的示例中查看用户如何使用socks_port ....
using-selenium-for-based-based-hostname-enumeration 和 gist.github.com
我认为,就您而言,您应该将port用作int而不是string。见下面的细节
首先让我们了解一下FF(或与Selenium一起使用的Web驱动程序)如何设置SOCKS代理。
对于Firefox,请在URL框中执行about:config。
network.proxy.socks;10.10.10.1
network.proxy.socks_port;8999
network.proxy.socks_remote_dns;true
network.proxy.socks_version;5
Run Code Online (Sandbox Code Playgroud)
您可以在FF Profile Director中的prefs.js中看到以下内容:
user_pref("network.proxy.socks", "10.10.10.1");
user_pref("network.proxy.socks_port", 8999);
user_pref("network.proxy.type", 1);
Run Code Online (Sandbox Code Playgroud)
请注意,network.proxy.socks是字符串,应仅将其设置为字符串。network.proxy.socks_port必须为int。
在使用selenium python模块设置它时:
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()
Run Code Online (Sandbox Code Playgroud)
请检查给定的首选项是否受支持并且在FF about:config列表中是否存在。
| 归档时间: |
|
| 查看次数: |
8523 次 |
| 最近记录: |