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 <name=string/file> 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 <file> 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程序设计有所帮助。
相关推荐
houmenghu 2020-11-17
kentrl 2020-11-10
逍遥友 2020-10-26
jincheng 2020-09-01
Blueberry 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
阳光之吻 2020-08-03
PkJY 2020-07-08
hzyuhz 2020-07-04
89407707 2020-06-27
服务器端攻城师 2020-06-26
阳光岛主 2020-06-25
笨重的蜗牛 2020-06-20
xuanwenchao 2020-06-14
Lophole 2020-06-13
明瞳 2020-06-12
songerxing 2020-06-11