【问题标题】:Using Selenium WebDriver + Tor as proxy使用 Selenium WebDriver + Tor 作为代理
【发布时间】:2018-03-22 18:44:08
【问题描述】:

我尝试使用 Selenium WebDriver Firefox 通过 TOR Socks5 在 9050 端口连接到特定站点,但无法建立连接。

profile = FirefoxProfile()    
profile.set_preference('network.proxy.type', 1)
profile.set_preference( "network.proxy.socks_version", 5 )
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference( "network.proxy.socks_remote_dns", True )    
browser = webdriver.Firefox(firefox_profile=profile)

该站点可能阻止了一些 TOR 连接,但奇怪的是我可以使用 TorBrowser 连接到它!我什至找到了 TorBrowser 使用的出口节点,并编辑了我的 torrc 文件以使用它(ExitNodes 'ip')。我检查了我的 selenium Firefox 的出口节点是否相同(我可以通过 TOR 代理成功连接到其他站点并检查我的 ip),但我仍然无法连接,即使使用相同的 ip!我的错在哪里?

第二件事是,如果我设置:

profile.set_preference('network.proxy.socks_port', 9150) 

即使用 TorBrowser 代理,selenium Firefox 成功建立到站点的连接。

我的 Tor 设置有问题吗?

【问题讨论】:

  • 你解决了吗?

标签: python selenium proxy tor firefox-profile


【解决方案1】:

使用 Selenium WebDriver、GeckoDriver 和 Firefox 通过端口 TOR Socks5 连接到特定站点 9050 您可以启动 tor 守护进程 并使用 FirefoxProfile 您可以使用以下解决方案:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

torexe = os.popen(r'C:\Users\AtechM_03\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\AtechM_03\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("http://check.torproject.org")

【讨论】:

    猜你喜欢
    • 2015-04-23
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多