python pycurl模块库的用法
用于从指定网址读取网页,主要是python pycurl模块的使用。
代码:
#!/usr/bin/env python
import pycurl
#定义一个类
class CallBack:
"""
for pycurl
"""
def __init__(self):
"""Constructor"""
self.data = ""
def func(self, data):
self.data = self.data + data
def urls(md5, location="", option={}):
c = pycurl.Curl()
f = CallBack()
c.setopt(pycurl.URL, "http://XXXXXX/getUrl.php?key=%s" % md5)
c.setopt(pycurl.WRITEFUNCTION, f.func)
c.perform()
c.close()
return f.data