简体   繁体   中英

how to scrape a list of data from a url using jquery

I need to scrape a json data from this url: https://www.google.com/finance/info?q=NSE:NIFTY using jquery. once its scarped i need to pass those value from respected key to a real time updating html table. i am really very new to this.. so please anyone can helping me out to solve this issue.

I tried to solve the same problem with ajax also.i am very new to this front end work so please help me out for solve this issue.

The url returns a JSONP object. You can use the ajax function of jQuery to receive the data as an javascript object and do further work with it ...

$.ajax({
    url: "https://www.google.com/finance/info?q=NSE:NIFTY",
    dataType: "jsonp",
    success: function(response) {
        if (response.length) {
            for (i = 0, l = response.length; i < l; i++) {
                // example, log property 't' of each entry to the console
                console.log(response[i].t);
            }
        }
    }
});

Working example.

You will have to go through the data and generate the html for it.

You can use the getJSON function of jquery to fetch the data

$.getJSON('https://www.google.com/finance/info?q=NSE:NIFTY&callback=?', function(data){
     console.log(data[0]);
 });

Since its a jsonp we need to add the callback param in the url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM