Last active
February 3, 2017 10:03
-
-
Save kurozumi/6f8b8f9bf7deac7e850af253a91c3d8f to your computer and use it in GitHub Desktop.
【Python】SOCKS5プロキシを利用してWEBページにアクセスする方法
This file contains 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
# coding: utf-8 | |
import socks | |
import socket | |
import urllib.request | |
try: | |
socks.set_default_proxy(socks.SOCKS5, "localhost", 1080) | |
socket.socket = socks.socksocket | |
url = "http://a-zumi.net" | |
request = urllib.request.Request(url) | |
with urllib.request.urlopen(request) as page: | |
print(page.read()) | |
except Exception as e: | |
print("Error:{}".format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment