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): https://www.binary.com/trading?l=EN
And finally here is the link to the JavaScript file of the website which have all the functions: https://static.binary.com/js/binary.min.js?13b386b
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
--------------------------------------------------------------------------------.---------------------------------------------------
Okay so the first part of the question is solved but i am having another issue now. I copied this code but i am getting this error now. Here is my code:
import java.net.URI;
import java.io.IOException;
import java.lang.InterruptedException;
import javax.websocket.*;
@ClientEndpoint
public class WSClient {
@OnOpen
public void onOpen(Session session) throws java.io.IOException
{
session.getBasicRemote().sendText("{\"ticks\": \"R_100\"}");
}
@OnMessage
public void onMessage(String message)
{
System.out.println("ticks update: " + message);
}
public static void main(String[] args)
throws IOException, DeploymentException, InterruptedException
{
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
URI apiUri = URI.create("wss://ws.binaryws.com/websockets/v3");
Session session = container.connectToServer(WSClient.class, apiUri);
Thread.sleep(10000);
}
}
And here is the error on console:
Exception in thread "main" java.lang.RuntimeException: Could not find an implementation class. at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73) at WSClient.main(WSClient.java:24)
This site is using WebSockets to retrieve the data from server to show in the client:
var onLoad = function(){
trading_page = 1;
if(sessionStorage.getItem('currencies')){
displayCurrencies();
}
BinarySocket.init({
onmessage: function(msg){
Message.process(msg); //this function is updating that sppan
},
onclose: function(){
processMarketUnderlying();
}
});
Price.clearFormId();
TradingEvents.init();
Content.populate();
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 .
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.