我有以下代码天气网站jsoup的Java
`
import java.io.IOException;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.*;
public class da {
/**
* @param args
*/
public static void main(String[] args) {
try {
Document doc=Jsoup.connect("http://www.vremea.net/").get();
Elements e=doc.select(".homeContent>ul>li ");
PrintStream ps=new PrintStream(new FileOutputStream("io"));
for(int i=0;i<e.size();i++)
{ps.println(e.get(i).text());
System.out.println(e.get(i).text());}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
` 我想访问这个网站http://www.vremea.net/并没有“归属的内容”,它有更多的“UL”每一个与“李”。我的代码遍历所有“ul”,但正如你可以在网站上看到的,它没有得到那些“ul”(我得到第二列,第三,第四,然后第一),我的问题是为什么它按此顺序?
编辑:什么可能是这样做的更通用的方式(我的意思是如果这个网站的所有者想修改结构能够得到这个列表像我这里没有修改代码)?
没有。你的输出就像我的,但是是错误的。如果你看下面的地图,你会看到有4列,如果你看看你的名字,你会发现你从第二个开始。这也是我发生的事情。 – User124235
对不起,我还没有得到它。 我正在看标题下方的地图“罗马尼亚的主要当地文化中的Vremea”。有4列,每个从左到右的第一个元素是“布加勒斯特”,“Carei”,“Medgidia”,“Satu Mare”。 我看到它们按字母顺序排列(从上到下,从左到右),但我也困惑为什么第一个以'B'开头。 – Nithanim
今天当我进入该网站的列在哪里像输出。我不知道为什么当我问这个问题时,他们在其他方面(在我的电脑上),但今天他们就像我的输出和output.thx无论如何你的时间来回应和搜索错误 – User124235