python- pycurl

import pycurl
import StringIO

buf = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://www.30wish.net')
c.setopt(pycurl.TIMEOUT, 15)
c.setopt(pycurl.FOLLOWLOCATION, 1) #允许跟踪来源
c.setopt(pycurl.MAXREDIRS, 5)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0')
c.setopt(pycurl.WRITEFUNCTION, buf.write) #将返回的内容定向到回调函数write

c.perform()
status_code = c.getinfo(pycurl.HTTP_CODE)       #返回的HTTP状态码
content_size = c.getinfo(pycurl.SIZE_DOWNLOAD)  #返回的数据的大小
content =buf.getvalue()
print status_code
print content_size

你可能感兴趣的:(python- pycurl)