本文介绍了通过 Tor 使用 Python 发出请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 Tor 向网页发出多个 GET 请求.我想为每个请求使用不同的 IP 地址.
I want to make multiple GET requests using Tor to a webpage. I want to use a different ipaddress for each request.
import socks
import socket
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9150)
socket.socket = socks.socksocket
import requests
print (requests.get('http://icanhazip.com')).content
使用这个,我提出了一个请求.如何更改 ipaddress 以创建另一个?
Using this, I made one request. How can I change the ipaddress to make another?
推荐答案
这里是你要使用的代码(使用pip install stem
下载stem包)
Here is the code you want to use (download the stem package using pip install stem
)
from stem import Signal
from stem.control import Controller
with 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")
祝你好运,希望能奏效.
Good luck and hopefully that works.
这篇关于通过 Tor 使用 Python 发出请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!