Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 试图从网站提取信息,但某些值显示为空?_Java_Html_Jsoup - Fatal编程技术网

Java 试图从网站提取信息,但某些值显示为空?

Java 试图从网站提取信息,但某些值显示为空?,java,html,jsoup,Java,Html,Jsoup,我已经使用JSoup工作和测试了一段时间,这个问题困扰了我一段时间 目前,这个类应该从这个网站的一个表中提取信息。这个程序可以从表中提取的唯一内容是 Code | Currency | fcu/CAD | fcu/USD | Code | Currency | fcu/CAD | fcu/USD 网站上显示的所有3个字母代码,但对于所有其他信息,如值和美元名称,程序显示为空。如果有人想知道px上升到34,ay上升

我已经使用JSoup工作和测试了一段时间,这个问题困扰了我一段时间

目前,这个类应该从这个网站的一个表中提取信息。这个程序可以从表中提取的唯一内容是

Code    |    Currency   |    fcu/CAD    |    fcu/USD    |    Code   |    Currency   |    fcu/CAD    |    fcu/USD 
网站上显示的所有3个字母代码,但对于所有其他信息,如值和美元名称,程序显示为空。如果有人想知道px上升到34,ay上升到16,因为这是我要从中提取的表的大小

public String CountryHandler2(int px, int ay) throws IOException{
    String url = "http://fx.sauder.ubc.ca/today.html";
    Document doc = Jsoup.connect(url).get();
    Elements paragraphs = doc.select("body > table:nth-child(4) > tbody:nth-child(1) > tr:nth-child("+px+") > td:nth-child("+ay+") > font:nth-child(1) > b:nth-child(1)");

    System.out.println("Paragraphs " + paragraphs.text());
    if(paragraphs.hasText()){  
        return paragraphs.text();
    }
    return null;
}

我尝试了这个,并且能够提取表数据。也许你可以这样试试

    public static void main (String [] args) throws IOException{
       Document doc = Jsoup.connect("http://fx.sauder.ubc.ca/today.html").get();
       Element table = doc.select("table").get(2); //get the 3rd table
       Elements trs = table.select("tr"); //get each row of that table
       for (Element e: trs){
          System.out.println(e.text());
       }
    }
请做一份报告。这里没有办法帮助你,因为我们没有问题本身的必要信息。另见。