Fetch Span Value on specific Website

时间:2016-04-21 22:06:18

标签: javascript java html

So i have a java code to fetch the values from a span. 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?

Here is my code and i am using 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?

1 个答案:

答案 0 :(得分:2)

您的问题是,如果使用javascript添加范围,则它不会作为您的代码获得的响应的一部分。

您需要确保您的代码可以像浏览器一样运行JS以获取结果并触发导致获得此结果的所有操作(如果有的话)。

我建议不要这样做,并为此获取适当的API源。