Created
September 29, 2011 23:10
-
-
Save zachwill/1252190 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| """ | |
| Use Tor through Python. Note, Tor must be running for the script to | |
| work properly. | |
| """ | |
| import urllib2 | |
| def use_tor(url): | |
| """Use Tor to open some URL.""" | |
| proxy = urllib2.ProxyHandler({'http': '127.0.0.1:8118'}) | |
| opener = urllib2.build_opener(proxy) | |
| opener.addheaders = [('User-agent', 'Mozilla/5.0')] | |
| return opener.open(url).read() | |
| if __name__ == '__main__': | |
| url = "http://www.google.com" | |
| print use_tor(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment