python-pycurl

695 ワード

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