Skip to content

Instantly share code, notes, and snippets.

@marians
Last active July 10, 2017 23:47
Show Gist options
  • Select an option

  • Save marians/4fbc15fefbcb6efceffc to your computer and use it in GitHub Desktop.

Select an option

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/
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