2010年08月27日 星期五 10:50
urllib2:
import urllib2, cookielib
url = "http://ypk.39.net/leibie.html"
headers = {'User-Agent': "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8", "Referer" :"http://ypk.39.net",}
cookie_support= urllib2.HTTPCookieProcessor(cookielib.CookieJar())
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
urllib2.urlopen(urllib2.Request(url, None, headers)).read()
得到的结果是 HTTP Error 403: Forbidden
pycurl :
import pycurl
import StringIO
from time import time
url = "http://ypk.39.net/leibie.html"
crl = pycurl.Curl()
crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.FOLLOWLOCATION, 1)
crl.setopt(pycurl.MAXREDIRS, 5)
crl.fp = StringIO.StringIO()
crl.setopt(pycurl.URL, url)
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
crl.perform()
print crl.fp.getvalue()
很顺利
请教各位 urllib2是哪里出错了呢?
我该怎么处理呢?
谢谢
Zeuux © 2024
京ICP备05028076号