Last active
November 29, 2021 01:13
-
-
Save Aleksey-Voko/dfc11f792cd4fdbd6177f8894036b877 to your computer and use it in GitHub Desktop.
Tor session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Tor session. | |
============ | |
# pip install torpy==1.1.6 | |
""" | |
from torpy.http.requests import TorRequests | |
def change_tor_session(url, tor_requests): | |
with tor_requests.get_session() as session: | |
return session.get(url) | |
if __name__ == '__main__': | |
# Opera Mobile (Presto rendering engine) | |
USER_AGENT = ('Opera/9.80 (Android 4.1.2; Linux; Opera Mobi/' | |
'ADR-1305251841) Presto/2.11.355 Version/12.10') | |
HEADERS = {'User-Agent': USER_AGENT} | |
BASE_URL = 'https://httpbin.org/ip' | |
COUNT = 10 | |
with TorRequests(headers=HEADERS) as requests: | |
for _ in range(COUNT): | |
response = change_tor_session(BASE_URL, requests) | |
print(response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment