how to send tor request to url in python with example code
To send a Tor request to a URL in Python, you can use the requests library along with the socks library. Here's an example code snippet:
import requests
import socks
import socket
# Set Tor proxy information
socks.set_default_proxy(socks.SOCKS5, "localhost", 9050)
socket.socket = socks.socksocket
# Set URL to send request to
url = "http://example.com"
# Send Tor request to URL
response = requests.get(url)
# Print response content
print(response.content)
Here, we first set the Tor proxy information using the set_default_proxy function from the socks library. We specify that we want to use SOCKS5 protocol, and that the proxy is running on localhost on port 9050.
Then, we set the URL that we want to send a request to.
Finally, we send the request using the requests.get function, and print the response content. The requests library will automatically use the Tor proxy to send the request, so the request will be anonymous
原文地址: https://www.cveoy.top/t/topic/dUkI 著作权归作者所有。请勿转载和采集!