实际上,我使用Selenium管理了Tor浏览器的控制,但是我意识到Tor电路(IP的更改)没有启用。那么是否存在启用它的方法?或使用称为(新身份)表单代码的新功能。
我的环境是Python 3.7,tbselenium 0.4.2和Tor Browser 9.0.2,谢谢大家。
这里是有关如何在chrome webdriver中使用Tor的示例脚本:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType
#tor
from stem import Signal
from stem.control import Controller
link = #some_url
prox='socks5://127.0.0.1:9150' #This connects Selenium to the Tor Port which then connects to a Tor network
while True:
with Controller.from_port(port = 9051) as controller: #this is how you get a new Identity!
controller.authenticate()
controller.signal(Signal.NEWNYM)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % prox) #sets conncection to your 9150 port aka Tor Network
#chrome_options.add_argument('--headless') #opens headless browser
driver = webdriver.Chrome('*path to your driver file*', chrome_options=chrome_options)
driver.get(link)
#perform selenium stuff
您需要安装stem
库,该库基本上是Python的Tor API。您还必须编辑torrc
文件。 Here您可以阅读所有操作方法。