chenqb 发表于 2018-8-7 10:21:35

Python学习-pycurl模块

pycurl.Curl()    #创建一个curl对象  
c.setopt(pycurl.CONNECTTIMEOUT,5)    #连接的等待时间,设置为0则不等待
  
c.setopt(pycurl.TIMEOUT,5)    #请求超时时间
  
c.setopt(pycurl.NOPROGRESS,0)    #是否屏蔽下载进度条,非0则屏蔽
  
c.setopt(pycurl.MAXREDIRS,5)    #指定HTTP重定向的最大数
  
c.setopt(pycurl.FORBID_REUSE,1)    #完成交互后强制断开连接,不重用
  
c.setopt(pycurl.FRESH_CONNECT,1)    #强制获取新的连接,即替代缓存中的连接
  
c.setopt(pycurl.DNS_CACHE_TIMEOUT,60)    #设置保存DNS信息的时间,默认为120秒
  
c.setopt(pycurl.URL,"http://www.baidu.com")    #指定请求的URL
  
c.setopt(pycurl.USERAGENT,"Mozilla/5.2(compatible;MSIE6.0;WindowsNT5.1;SV1;.NETCLR1.1.4322;.NETCLR2.0.50324)")#配置请求HTTP头的User-Agent
  
c.setopt(pycurl.HEADERFUNCTION,getheader)    #将返回的HTTPHEADER定向到回调函数getheader
  
c.setopt(pycurl.WRITEFUNCTION,getbody)    #将返回的内容定向到回调函数getbody
  
c.setopt(pycurl.WRITEHEADER,fileobj)    #将返回的HTTPHEADER定向到fileobj文件对象
  
c.setopt(pycurl.WRITEDATA,fileobj)    #将返回的HTML内容定向到fileobj文件对象
页: [1]
查看完整版本: Python学习-pycurl模块