我想在 Linux mint 机器上使用 tbselenium 包来实现浏览器自动化。 当我尝试运行应该可以工作的代码时,python 给出了错误消息:
tbselenium.exceptions.TBDriverPortError: SOCKS port 9050 is not listening
我尝试使用的代码是:
from tbselenium.tbdriver import TorBrowserDriver
import time
with TorBrowserDriver("/home/sas/Videos/tor-browser_en-US/") as driver:
driver.get("https://github.com/mozilla/geckodriver")
有人知道为什么会这样吗? 满意的答案:)
编辑: 我唯一开放的端口是 5060
最佳答案
您可以尝试运行apt get install tor
来下载tor服务,然后只需在终端中运行tor
即可在端口9050(默认情况下)上启动代理。
现在您需要配置您的 Firefox 驱动程序以通过 Tor 实例代理 http 请求。
from selenium import webdriver
fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", "127.0.0.1")
fp.set_preference("network.proxy.http_port", 9050)
fp.set_preference("network.proxy.https", "127.0.0.1")
fp.set_preference("network.proxy.https_port", 9050)
driver = webdriver.Firefox(firefox_profile=fp)
driver.get("https://google.com")
如果您想以这种方式执行此操作,我认为您将无法使用 tbselenium
包,但这并不重要。
如果您无法正常工作,请告诉我您收到的错误。
关于python - 端口 9050 未监听 tb selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55975892/