我用 Java 编写了一个函数,通过它们的 ID 从给定的 URL 中获取 10 个链接。HTML 代码中的href
标签 ID 写为:id-1
、id-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 的任何问题。