imoteb imoteb - 7 months ago 24
HTML Question

Jsoup link selection

I am trying to get all the links inside the

div class news column index
here is the structure of the html:

enter image description here

And here what I have tried but actually it doesnt give me any result, I dont really know why :///

Document doc = Jsoup.connect("http://www.gsmarena.com/").get();
Elements els = doc.select("#body > div > div.news-column-index > ul");
for(Element e : els)
{
System.out.println(e.attr("href"));
}


EDIT: this is the URL I am parsing: http://www.gsmarena.com/

Answer

This works fine for me:

String str="http://www.gsmarena.com/"; Document doc=Jsoup.connect(str).userAgent(" Mozilla//5.0 (Windows NT 6.1; WOW64) AppleWebKit//537.36 (KHTML, like Gecko) Chrome//49.0.2623.110 Safari//537.36").get();
Elements links = doc.select("li[class=news-column-list-item]");

for (Element link : links) {

    System.out.println(link.select("a[href]").attr("href"));
}
Comments