V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hititan
V2EX  ›  问与答

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

  •  
  •   hititan · 2017-07-07 22:33:01 +08:00 · 3611 次点击
    这是一个创建于 2714 天前的主题,其中的信息可能已经有所发展或是发生改变。

    小弟不才,请大佬给与指点一下: 浏览器直接访问: 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

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

    2 条回复    2017-07-08 00:28:27 +08:00
    bosshida
        1
    bosshida  
       2017-07-07 23:50:39 +08:00 via iPhone
    加 headers 试试
    oh
        2
    oh  
       2017-07-08 00:28:27 +08:00
    我用 postman 测了一下得到的数据和浏览器访问的是一致的,没有加 user-agent 或其它 header
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2493 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 00:29 · PVG 08:29 · LAX 16:29 · JFK 19:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.