dongzhan8001 2016-02-24 20:53 采纳率: 0%
浏览 64
已采纳

获取网页的内容并放在数组或字符串中

I am not really sure how to phrase this question, so I will just ask the best I can.

I would like to know how to grab the contents of a webpage and place it in a string or array so I can parse the data.

This is the webpage: https://campusdata.uark.edu/api/buses?callback=?&routeIds=8

The webpage returns something like this:

?([{"id":25,"fleet":15,"name":"Fleet 15","description":"","zonarId":9,"gpsId":"8061088","latitude":"36.0680039","longitude":"-94.1758039","speed":0.000,"heading":89.700,"power":true,"date":"\/Date(1456339080000)\/","color":"#0090ff","routeName":"Blue","routeId":8,"distance":9999999999,"nextStop":"Garland Center","nextArrival":"8 mins"},{"id":33,"fleet":6,"name":"Fleet 6 ","description":"","zonarId":13,"gpsId":"8061090","latitude":"36.0818423","longitude":"-94.1707598","speed":0.000,"heading":181.700,"power":true,"date":"\/Date(1456339200000)\/","color":"#0090ff","routeName":"Blue","routeId":8,"distance":2.31887983012931,"nextStop":"South Creekside","nextArrival":"1 mins"}]);

I am not sure the best way to go about this... AJAX through JQuery? Maybe a php call? I don't know.

I have searched for this, but like I said, I don't know exactly how to phrase the question, so my search results have been sporadic at best. Can someone help me please?

  • 写回答

3条回答 默认 最新

  • douan4106 2016-02-24 21:06
    关注

    Seems like a JSONP call. You can use jQuery to easily fetch the data from the API end point. Please see the example below:

    $.ajax({
            url: "https://campusdata.uark.edu/api/buses?callback=?&routeIds=8",
    
            // The name of the callback parameter
            jsonp: "callback",
    
            // Tell jQuery we're expecting JSONP
            dataType: "jsonp",
    
            data: {},
    
            // Work with the response
            success: function( response ) {
                console.log( response ); // server response
            }
        });
    

    Here is a jsfiddle with working example. Please make sure to include jquery in the page before trying this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加