Last active
July 10, 2017 23:47
-
-
Save marians/4fbc15fefbcb6efceffc to your computer and use it in GitHub Desktop.
Using Tor Browser Bundle for anonymous HTTP requests in Python - supplement for http://www.sendung.de/2014-09-16/anonymous-scraping-via-python-tor/
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
| import socket | |
| import socks # pip install PySocks - https://github.com/Anorov/PySocks | |
| # configure default proxy. 9150 is the Tor Browser Bundle socks proxy port | |
| socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9150) | |
| socket.socket = socks.socksocket | |
| import urllib | |
| print(urllib.urlopen('http://icanhazip.com').read()) | |
| import urllib2 | |
| print(urllib2.urlopen('http://icanhazip.com').read()) | |
| import requests | |
| print(requests.get('http://icanhazip.com').text) | |
| import mechanize | |
| from mechanize import Browser | |
| br = Browser() | |
| print(br.open('http://icanhazip.com').read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment