uncurl 接口数据变python代码
简介:
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$
上一篇: mongo客户端升级导致pymongo中使用聚合函数时出现异常
下一篇: 封装 axios