当前位置: 萬仟网 > IT编程>脚本编程>Python > uncurl 接口数据变python代码

uncurl 接口数据变python代码

2020年01月17日 14:56  | 萬仟网IT编程  | 我要评论

简介:

uncurl是一个库,允许您将curl请求转换为使用 的python代码。由于chrome网络检查器具有的“copy as curl”,因此该工具对于用python重新创建浏览器请求很有用。

安装:

(venv) zhangdemacbook-pro:pythonclass test$ pip install uncurl

使用步骤:(google chrome浏览器) 抓取百度新闻数据

google浏览器选择开发者工具,进入开发者模式

 

 

 

 

 

 

 

 

 

 

 

3.打开pycharm,安装过uncurl 

uncurl "复制百度界面的curl格式数据"

(venv) zhangdemacbook-pro:pythonclass test$ uncurl "curl 'http://news.baidu.com/passport' -h 'connection: keep-alive' -h 'accept: application/json, text/javascript, */*; q=0.01' -h 'x-requested-with: xmlhttprequest' -h 'user-agent: mozilla/5.0 (macintosh; intel mac os x 10_14_4) applewebkit/537.36 (khtml, like gecko) chrome/79.0.3945.117 safari/537.36' -h 'referer: http://news.baidu.com/' -h 'accept-encoding: gzip, deflate' -h 'accept-language: zh-cn,zh;q=0.9' -h 'cookie: bidupsid=b4118d1eac1c90f87904beaf72f66215; pstm=1578995919; baiduid=b4118d1eac1c90f8dffc8d1114c47930:fg=1; localgx=%u5317%u4eac%7c%30%7c%u5317%u4eac%7c%30; bdorz=b490b5ebf6f3cd402e515d22bcda1598; h_ps_pssid=1423_21119_30492_26350_30499; delper=0; psino=2; hm_lvt_e9e114d958ea263de46e080563e254c4=1579054369,1579055803,1579139547,1579169647; hm_lpvt_e9e114d958ea263de46e080563e254c4=1579169647' --compressed --insecure"

requests.get("http://news.baidu.com/passport",
headers={
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-encoding": "gzip, deflate",
"accept-language": "zh-cn,zh;q=0.9",
"connection": "keep-alive",
"referer": "http://news.baidu.com/",
"user-agent": "mozilla/5.0 (macintosh; intel mac os x 10_14_4) applewebkit/537.36 (khtml, like gecko) chrome/79.0.3945.117 safari/537.36",
"x-requested-with": "xmlhttprequest"
},
cookies={
"baiduid": "b4118d1eac1c90f8dffc8d1114c47930:fg=1",
"bdorz": "b490b5ebf6f3cd402e515d22bcda1598",
"bidupsid": "b4118d1eac1c90f87904beaf72f66215",
"h_ps_pssid": "1423_21119_30492_26350_30499",
"hm_lpvt_e9e114d958ea263de46e080563e254c4": "1579169647",
"hm_lvt_e9e114d958ea263de46e080563e254c4": "1579054369,1579055803,1579139547,1579169647",
"localgx": "%u5317%u4eac%7c%30%7c%u5317%u4eac%7c%30",
"psino": "2",
"pstm": "1578995919",
"delper": "0"
},
verify=false
)
(venv) zhangdemacbook-pro:pythonclass test$

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

◎已有 0 人评论

Copyright © 2020  萬仟网 保留所有权利. 粤ICP备17035492号-1
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com