简体   繁体   English

在特定网站上获取跨度值

[英]Fetch Span Value on specific Website

So i have a java code to fetch the values from a span. 所以我有一个Java代码来从范围中获取值。 But the values comes null. 但是值变为空。 now i am not sure what might be the issue. 现在我不确定可能是什么问题。 If the span is written in javascript, is it possible to extract those values from the span using Java on eclipse? 如果span是用javascript编写的,是否可以在eclipse上使用Java从span中提取这些值?

Here is my code and i am using JSoup: 这是我的代码,我正在使用JSoup:

public static void main(String[] args) throws IOException{

    Document document = Jsoup.connect("https://www.binary.com/trading?l=EN").userAgent("Mozilla").get();
    Elements elements = document.select("span#spot");
    for (Element element : elements) {
      System.out.println(element.text());
    }


}

} }

As mentioned earlier, i get no values on console. 如前所述,我在控制台上没有任何值。 But if i try this on other websites, i get the data with no issues. 但是,如果我在其他网站上尝试使用此工具,则不会出现任何问题。 Is there anyway to fetch these values? 无论如何要获取这些值?

Your problem is if the span is added using javascript, it's not present as part of the response your code gets. 您的问题是,如果使用javascript添加了跨度,那么它就不会作为代码获得的响应的一部分。

You need to ensure that your code can run JS just like browser would to obtain the result and trigger all the actions that lead to obtaining this result if any. 您需要确保您的代码可以运行JS,就像浏览器将获取结果并触发导致获取此结果的所有操作(如果有)一样。

I would recommend against doing this, and reside to obtaining proper API source for this. 我建议不要这样做,而应该为此获取适当的API源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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