if there is a way to use d3 to parse finance.google url ?

25 views
Skip to first unread message

Vincent Dong

unread,
Dec 9, 2016, 2:51:12 AM12/9/16
to d3...@googlegroups.com
hey folks, 

I am trying to load use javascript to write a live price monitor, by reading the following link :   https://finance.google.com/finance/info?client=ig&q=goog    .

It looks like a good jason source except that there is // in the front, so I can not directly use d3.jason to read it.

What would be the best way for this case to get the return content into jason format ? 

thanks.

Best Regards
Vincent

Vlado Z

unread,
Dec 9, 2016, 6:13:18 AM12/9/16
to d3-js, Vincen...@gmail.com
You can try something like this:

/**
 * @param {Object} jq
 * @param {Object} d3
 */

(function(jq, d3) {
   
'use strict';

   
var request = d3.request("https://finance.google.com/finance/info?client=ig&q=goog", function (error, data) {
       
var jsonString = "",
            jsonDataArray
= [],
            jsonObject
= {};

       
if (error) {
           
throw error;
       
}

        console
.dir(data);

        jsonDataArray
= data.responseText.split("//");
        jsonString
= jsonDataArray[1].trim();
        console
.log(jsonString);

        jsonObject
= JSON.parse(jsonString);
        console
.dir(jsonObject);
   
});

}($, d3));


Vincent Dong

unread,
Dec 10, 2016, 3:55:38 PM12/10/16
to d3...@googlegroups.com
thanks .  that works. 
also found jquery works:

$.getJSON("https://finance.google.com/finance/info?client=ig&q=goog&callback=?", function(data) {
console.log(data)
});

Vincent.


--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vlado Z

unread,
Dec 11, 2016, 2:59:57 PM12/11/16
to d3-js, Vincen...@gmail.com
What you think is best.

The biggest problem were those two lines in front. d3.json() didn't understand the response of json with the two dashes in front, so d3.request() gives you more flexibility, to process the data before using it.

d3.json() must receive data in json format to work.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages