作者:圣菁振婷玉勇 | 来源:互联网 | 2018-07-18 07:27
这篇文章主要介绍了Python基于PycURL自动处理cookie的方法,实例分析了Python基于curl操作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程序设计有所帮助。