入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

python操作cookie ,curl请求

创建时间:2017-05-23 投稿人: 浏览次数:923

Python实现登陆后产生的cookie请求

import cookielib
import urllib2
import urllib

c = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c))
login_path = "urllogin"
data = {"username":"******", "password":"******","isEncypted":"false"}
post_info = urllib.urlencode(data)
request = urllib2.Request(login_path, post_info)

html = opener.open(request)
for item in c:
    print item.name
    print item.value
handerl = urllib2.HTTPCookieProcessor(c)
opener = urllib2.build_opener(handerl)
res = opener.open("url")
print res.read()

curl利用cookie请求

#http请求可以查到数据
curl -s --header "Content-Type:application/x-www-form-urlencoded; charset=UTF-8" -O -c cookie -d "username=******&password=******&isEncypted=false" url
curl -s --header "Content-Type:application/json; Accept-Encoding:"zip, deflate"; Accept-Language:"zh-CN,zh;q=0.8";X-Requested-With:XMLHttpRequest" -b cookie -X GET "url"

curl利用cookie实现restful 请求

curl -s --header "Content-Type:application/x-www-form-urlencoded; charset=UTF-8" -O -c cookie -d "username=******&password=******&isEncypted=false" url
curl -b cookie -X GET url
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像