现在的位置: 首页 > 综合 > 正文

Pycur读取Response Header

2012年12月11日 ⁄ 综合 ⁄ 共 581字 ⁄ 字号 评论关闭

见代码:

 

#!/usr/bin/python

import pycurl
import sys

class Storage:
    def __init__(self):
        self.contents = ''
        self.line = 0

    def store(self, buf):
        self.line = self.line + 1
        self.contents = "%s%i: %s" % (self.contents, self.line, buf)

    def __str__(self):
        return self.contents

retrieved_body = Storage()
retrieved_headers = Storage()
c = pycurl.Curl()
c.setopt(c.URL, 'http://www.demaziere.fr/eve/')
c.setopt(c.WRITEFUNCTION, retrieved_body.store)
c.setopt(c.HEADERFUNCTION, retrieved_headers.store)
c.perform()
c.close()
print retrieved_headers
print retrieved_body

 

 

via:http://stackoverflow.com/questions/472179/how-to-read-the-header-with-pycurl

【上篇】
【下篇】

抱歉!评论已关闭.