Created
October 18, 2013 16:08
-
-
Save lavarini/7043827 to your computer and use it in GitHub Desktop.
Urllib com proxy
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 urllib2 | |
from bs4 import BeautifulSoup | |
import re | |
import time | |
from StringIO import StringIO | |
import gzip | |
def make_request(url): | |
proxy_support = urllib2.ProxyHandler({"http":"http://187.32.127.161:3128"}) | |
opener = urllib2.build_opener(proxy_support) | |
urllib2.install_opener(opener) | |
f = urllib2.urlopen(url) | |
# request = urllib2.Request(url) | |
# request.add_header('Accept-encoding', 'gzip') | |
# response = urllib2.urlopen(request) | |
# buf = StringIO( response.read()) | |
# f = gzip.GzipFile(fileobj=buf) | |
data = f.read() | |
return BeautifulSoup(data) | |
def main(): | |
temp = make_request('http://mangafox.me/manga/naruto/v66/c631/1.html') | |
import pdb | |
pdb.set_trace() | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment