python基于pycurl自动处理cookie的方法

本文实例讲述了python基于pycurl自动处理cookie的方法。分享给大家供大家参考。具体如下:

import pycurl
import stringio
url = “http://www.google.com/”
crl = pycurl.curl()
crl.setopt(pycurl.verbose,1)
crl.setopt(pycurl.followlocation, 1)
crl.setopt(pycurl.maxredirs, 5)
crl.fp = stringio.stringio()
crl.setopt(pycurl.url, url)
crl.setopt(crl.writefunction, crl.fp.write)
# option -b/–cookie cookie string or file to read cookies from
# note: must be a string, not a file object.
crl.setopt(pycurl.cookiefile, “cookie_file_name”)
# option -c/–cookie-jar write cookies to this file after operation
# note: must be a string, not a file object.
crl.setopt(pycurl.cookiejar, “cookie_file_name”)
crl.perform()
print crl.fp.getvalue()

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

Posted in 未分类

发表评论