How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?
Usually a socks server listens at one port which is by default port 1080. This is used by all socksified applications. To look only for one port facilitates management and monitoring of network traffic.
Click the Apple icon at the top left of the menu bar on your screen and select System Preferences. Select Network and then Proxies. Click the Advanced button to access the Network settings and navigate to the Proxies tab. Click the SOCKS Proxy checkbox and enter the host and port information.
SOCKS5 is the improved and latest version of the SOCKS protocol, SOCKS5 proxy is more secure than SOCKS4 because it establishes a full TCP connection and it also uses SSH encrypted tunneling method to relay the traffic i.e. a user can set up an SSH tunnel to send their unencrypted data over a network through an ...
You can use SocksiPy module. Simply copy the file "socks.py" to your Python's lib/site-packages directory, and you're ready to go.
You must use socks before urllib2. (Try it pip install PySocks
)
For example:
import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 8080) socket.socket = socks.socksocket import urllib2 print urllib2.urlopen('http://www.google.com').read()
You can also try pycurl lib and tsocks, for more detail, click on here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With