Home  >  Article  >  Backend Development  >  python中pycurl库的用法实例

python中pycurl库的用法实例

WBOY
WBOYOriginal
2016-06-16 08:41:291174browse

本文实例讲述了python中pycurl库的用法,分享给大家供大家参考。

该实例代码实现从指定网址读取网页,主要是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

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn