Mohamed Mohamed - 2 years ago 79
Javascript Question

How to take span value from website which stores data dynamically using JavaScript

I am new to this so could anyone point me to the right direction?
I have a JavaScript file by which i want to take the value of a span from a website. Now the website dynamically refreshes the span every 1 second. I am using Java (Eclipse) to fetch this data. When i try to take the span value from website, it gives me no values because the span uses JavaScript to store these values. I already asked this question and i will drop a link below. So all i want to know is, how to take this data dynamically using JSoup. Someone commented on my last post saying the JavaScript might be querying a web service and to find that code. But i could not find the code and i don't know what to do next.

Here is the link to my last question: Fetching Dynamic Website Data Using Java

Here is the link to the website which stores data i want in a span named "id=spot" (Basically numeric numbers of stock):

And finally here is the link to the JavaScript file of the website which have all the functions:

Please help me as i am very new to this and i have spent more than 2 days trying to find the answer with no luck.
Thank you in advance

Answer Source

This site is using WebSockets to retrieve the data from server to show in the client:

var onLoad = function(){
        trading_page = 1;
            onmessage: function(msg){
                Message.process(msg); //this function is updating that sppan
            onclose: function(){

So you can not see the data in downloaded HTML with JSOUP. You need a UI-less Browser in java like HTML-UNIT.

But the preferred and more reasonable way is to use the API of the site.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download