java - How can I find Time from defined URL using Jsoup? -
i working in java , using jsoup. want find time below url. tried these unable it. time lies in span tag under id(timestamp--time timeago) trying not know problem.
document doc; elements lin = null; string url = "http://www.dawn.com/news/1277133/this-is-how-pakistanis-around-the-country-are-celebrating-independence-day"; try { doc = jsoup.connect(url).timeout(20*1000).useragent("chrome").get(); lin = doc.getelementsbyclass("span.timestamp--time timeago"); // system.out.println(lin); } catch (ioexception e) { e.printstacktrace(); } int i=0; for(element l :lin){ system.out.println(""+i+ " : " +l.text()); i++; }
replace
lin = doc.getelementsbyclass("span.timestamp--time timeago"); with
lin = doc.select("span.timestamp--time.timeago"); output:
0 : aug 14, 2016 04:29pm 1 : aug 14, 2016 12:39pm 2 : aug 14, 2016 01:34pm 3 : aug 14, 2016 01:37pm 4 : aug 14, 2016 04:19pm 5 : aug 15, 2016 01:11am 6 : aug 15, 2016 08:49am 7 : aug 16, 2016 12:32pm from wording in api getelementsbyclass accepts single classname. in case lin = doc.getelementsbyclass("timestamp--time"); gives same output, if want select multiple classes select better choice.
Comments
Post a Comment