JSoup从元素列表创建数组列表

时间:2013-01-04 03:25:56

标签: java jsoup

所以我从一个页面使用JSoup抓取一个大的元素列表。当我说大的时候,我的意思就像几百个元素。我知道元素存在,因为我将它们全部转换为一个巨大的字符串,它们都被列出来了。现在我需要做的就是把它们放到一个数组中,这样我就可以1比1处理它们。这是我现在的代码:

    public static String [] grabWordList(String ending) throws IOException, InterruptedException{

Document doc = Jsoup.connect("http://site.com/").get();
Elements links = doc.getElementsByClass("defLink"); //Get words from site
String s[] = new String[links.size()]; //Create an array

int i = 0;
for(Element el : links){  //Attempt to put them into an array using this loop of blindly coppy and pasted code (I know, HORRIBLE Idea, I dont usually do that, but I am lost)
    s[i++] = el.attr("links");
}
 return s;
    }

当我这样做时,我使用此代码尝试抓取阵列并打印它:

String words[] = Methods.grabWordList("in");

   for(int j=0; j < words.length; j++){
       System.out.println(words[j]);
   }

运行此代码时,所有打印的内容都是[Ljava.lang.String;@6201dbc 我希望有人可以提供帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

我个人认为,“字符串字[]”字应该被定义为“字符串[]”,就像在Java中创建一个数组一样。但是我对JSoup并不熟练。