requests.get 获取的数据跟浏览器不一样,请问是怎么回事,以及如何解决?

2017-07-07 22:33:01 +08:00
 hititan

小弟不才,请大佬给与指点一下: 浏览器直接访问: https://yunbi.com//api/v2/tickers.json 可以得到数据 ,数据如下: {"btscny":{"at":1499437552,"ticker":{"buy":"1.29","sell":"1.2989","low":"1.2552","high":"1.488","last":"1.2989","vol":"22699215.34"}},"dgdcny":{"at":1499437552,"ticker":{"buy":"440.1","sell":"449.99","low":"440.1","high":"519.0","last":"444.31","vol":"3584.5416"}},"eoscny":{"at":1499437552,"ticker":{"buy":"18.76","sell":"18.79","low":"18.14","high":"23.7","last":"18.76","vol":"21589228.2"}},"zmccny":{"at":1499437552,"ticker":{"buy":"3.62","sell":"3.64","low":"3.61","high":"3.79","last":"3.64","vol":"1000131.94"}},"ethcny":{"at":1499437552,"ticker":{"buy":"1716.83","sell":"1720.0","low":"1708.33","high":"1912.0","last":"1720.0","vol":"41138.7311"}},"1stcny":{"at":1499437552,"ticker":{"buy":"6.68","sell":"6.693","low":"6.33","high":"8.357","last":"6.68","vol":"6911844.041"}},"btccny":{"at":1499437552,"ticker":{"buy":"17530.6","sell":"17655.93","low":"17450.0","high":"18326.0","last":"17528.48","vol":"1833.3871"}},"etccny":{"at":1499437552,"ticker":{"buy":"115.5","sell":"115.9","low":"115.0","high":"124.8","last":"115.5","vol":"177334.222"}},"gxscny":{"at":1499437552,"ticker":{"buy":"23.25","sell":"23.299","low":"22.2","high":"31.66","last":"23.299","vol":"4412422.437"}},"qtumcny":{"at":1499437552,"ticker":{"buy":"51.81","sell":"52.0","low":"50.18","high":"62.0","last":"51.81","vol":"635315.869"}},"repcny":{"at":1499437552,"ticker":{"buy":"173.0","sell":"176.97","low":"173.0","high":"195.0","last":"179.43","vol":"3157.361"}},"gntcny":{"at":1499437552,"ticker":{"buy":"2.61","sell":"2.62","low":"2.6","high":"3.076","last":"2.62","vol":"1399876.0"}},"sccny":{"at":1499437552,"ticker":{"buy":"0.0694","sell":"0.0699","low":"0.068","high":"0.0885","last":"0.0694","vol":"337006202.0"}},"anscny":{"at":1499437552,"ticker":{"buy":"47.5","sell":"47.875","low":"46.1","high":"54.499","last":"47.875","vol":"706340.398"}},"zeccny":{"at":1499437552,"ticker":{"buy":"1718.0","sell":"1719.0","low":"1700.0","high":"1986.0","last":"1719.0","vol":"8257.776"}}}

但用 : h=requests.get('https://yunbi.com//api/v2/tickers.json') print h.text

看到的数据却不一样。 请问该如何获取里面的数据呢? 感谢

3625 次点击
所在节点    问与答
2 条回复
bosshida
2017-07-07 23:50:39 +08:00
加 headers 试试
oh
2017-07-08 00:28:27 +08:00
我用 postman 测了一下得到的数据和浏览器访问的是一致的,没有加 user-agent 或其它 header

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/373834

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX