【发布时间】:2020-01-03 05:18:45
【问题描述】:
我想使用 tbselenium 包进行浏览器自动化,但是当我尝试运行代码时出现以下错误 TBDriverPortError: SOCKS port 9050 is not listener.
以下是我用过的代码sn-p。
import unittest
from time import sleep
from tbselenium.tbdriver import TorBrowserDriver
import tbselenium.common as cm
class TestSite(unittest.TestCase):
def setUp(self):
# Point the path to the tor-browser_en-US directory in your system
tbpath = r'C:\Users\Sachin\Desktop\Tor Browsernew'
self.driver = TorBrowserDriver(tbpath, tbb_logfile_path='test.log')
self.url = "https://check.torproject.org"
def tearDown(self):
# We want the browser to close at the end of each test.
self.driver.close()
def test_available(self):
self.driver.load_url(self.url)
# Find the element for success
element = self.driver.find_element_by_class_name('on')
self.assertEqual(str.strip(element.text),
"Congratulations. This browser is configured to use Tor.")
sleep(2) # So that we can see the page
if __name__ == '__main__':
unittest.main()
谁能帮我解决这个错误已经苦苦挣扎了好几天了
【问题讨论】:
-
嗨 sachin,端口 9050 是我在 google 上找到的 Versiera Agent Listener。您是否尝试使用任何其他端口并发现相同的问题?
-
嗨@RaHuL实际上我需要专门使用tor浏览器,它只使用端口9050,所以浏览器打开但没有响应的其他端口
-
尝试关闭防火墙并尝试相同。有时防火墙会阻止该端口。谢谢
-
您需要从 Torrc 文件中取消注释 ControlPort、HashedControlPassword 和 CookieAuthentication。
-
你的 torrc 文件必须是 github.com/torproject/tor/blob/master/src/config/… 这样的内容,或者你可以手动粘贴。你用的是哪个操作系统?
标签: python python-3.x selenium web-scraping tor