Java 试图从网站提取信息,但某些值显示为空?
我已经使用JSoup工作和测试了一段时间,这个问题困扰了我一段时间 目前,这个类应该从这个网站的一个表中提取信息。这个程序可以从表中提取的唯一内容是Java 试图从网站提取信息,但某些值显示为空?,java,html,jsoup,Java,Html,Jsoup,我已经使用JSoup工作和测试了一段时间,这个问题困扰了我一段时间 目前,这个类应该从这个网站的一个表中提取信息。这个程序可以从表中提取的唯一内容是 Code | Currency | fcu/CAD | fcu/USD | Code | Currency | fcu/CAD | fcu/USD 网站上显示的所有3个字母代码,但对于所有其他信息,如值和美元名称,程序显示为空。如果有人想知道px上升到34,ay上升
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());
}
}
请做一份报告。这里没有办法帮助你,因为我们没有问题本身的必要信息。另见。