I wrote a function in Java to fetch 10 links by their IDs from a given URL. The href tag IDs in the HTML code are written as: id-1, id-2, etc. I’m using JSoup library. My code is:
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
}
}
The output I get is always null. This is my first time to use JSoup and when I tried to ask in JSoup website, it guids me to Stack Overflow for any questions regarding JSoup.
Try