java - Jsoup iterate over Elements causes duplicated output -
i have page link extract data (i want tables' tds attributes).
i used for-loop iteration via elements have extract attributes of . duplicated output.
the output should output @ image on end of post
document doc = jsoup.connect("http://www.saudisale.com/ss_a_mpg.aspx").get(); elements elements = doc.select("table").select("tbody").select("tr").select("td") ; for(element e:elements) { system.out.println(e.select("span[id~=label4]").text() + "\t" + e.select("input[id$=imagebutton1]").attr("src") + "\t" + "" + e.select("span[id~=label13]").text()); }
this output them, duplicated!!! :
the output should this:-
would please try below code?
elements description = doc.select("tbody"); doc=jsoup.parse(description.html()); description = doc.select("td"); for(int j = 0; j < description.size(); ++ j) { string bodytext = description.eq(j).text(); // bodytext text of each td }