中培伟业IT资讯频道
您现在的位置:首页 > IT资讯 > 软件研发 > 如何使用Python通过Tor浏览器发出请求

如何使用Python通过Tor浏览器发出请求

2020-07-17 18:10:00 | 来源:中培企业IT培训网

Python编程语言是个十分神奇的技术,利用Python可以改变网页前端你想要变换的模样。所以有人就提问了,如何使用Python通过Tor浏览器发出请求?如果要使用Python3,我们将要使用一个Python库控制器超过Tor的请求的Tor称为干。为此,您需要为您的操作系统安装茎包。下面是一些简单的操作命令,通过这些命令的操作,您就能实现Python通过Tor浏览器发出的请求了。

· 对于MacOS:

pip3 install stem

· 在python3 venv中(推荐)。

· 对于Ubuntu:

sudo pip3 install stem

· 在python3 venv中(推荐)。

from stem import Signalfrom stem.control import Controllerwith Controller.from_port(port = 9051) as controller:

controller.authenticate(password='your password set for tor controller port in torrc')

print("Success!")

controller.signal(Signal.NEWNYM)

print("New Tor connection processed")

但是,您尚未完成。您可能会收到此错误:

error(61, 'Connection refused')

这是因为您的计算机上尚未打开端口9051。

要解决此问题,您需要编辑torrc文件并取消注释相应的行。

ControlPort 9051## If you enable the controlport, be sure to enable one of these## authentication methods, to prevent attackers from accessing it.

HashedControlPassword16:

要生成密码,请运行:

tor --hash-password ""

哪里是您要设置的密码。

通过Tor发出请求已完成。

注意:要运行

tor

命令,您需要

tor

软件包已安装。对于macOS,可以使用以下命令轻松安装

brew install tor。

以上就是关于如何使用Python通过Tor浏览器发出请求的全部内容介绍,想了解更多关于如何使用Python的信息,请继续关注中培伟业。

标签: Python 软件研发