0

我用 Java 编写了一个函数,通过它们的 ID 从给定的 URL 中获取 10 个链接。HTML 代码中的href标签 ID 写为:id-1id-2等。我使用的是 JSoup 库。我的代码是:

    public static void linkList(String URL)
       {
          Document doc=Jsoup.parse(URL);
          Element e;
          int eId=1;

              for(int x=1; x<=10; x++)
              {
                //element ids: id-1, id-2, etc.. 
                e = doc.getElementById("id-"+eId); 
               System.out.println(e); //print the link
               eId++; //increment the id to fetch the next
              }
       } 

我得到的输出总是null. 这是我第一次使用 JSoup,当我尝试在 JSoup 网站上提问时,它会引导我到 Stack Overflow 询问有关 JSoup 的任何问题。

4

1 回答 1

0

尝试

String elementText = e.text(); 
于 2012-06-23T12:40:43.743 回答