I'm trying to extract specific data from html <a>
Tag. I want to extract the imgurl
and the surl
. Here is the HTML code:
<a href="/images/search?q=nba&view=detailv2&&&
id=FE19E7BB2916CE8B6CD78148F3BC0656D151049A&
selectedIndex=3&
ccid=2%2f7OBkGc&
simid=608035681734625885&
thid=JN.tdPCsRj4HyJzbwA%2bgXsS8g"
ihk="JN.tdPCsRj4HyJzbwA+gXsS8g"
m="{ns:"images",k:"5070",dirovr:"ltr",
mid:"FE19E7BB2916CE8B6CD78148F3BC0656D151049A",
surl:"http://www.nba.com/gallery/rookie/070727_1.html",
imgurl:"http://www.nba.com/media/draft_class_3_07_070727.jpg
",
ow:"300",docid:"608035681734625885",oh:"192",tft:"58"}"
mid="FE19E7BB2916CE8B6CD78148F3BC0656D151049A"
t1="The 2007 NBA Draft Class"
t2="625 x 400 · 374 kB · jpeg"
t3="www.nba.com/gallery/rookie/070727_1.html"
h="ID=images,5070.1"><img data-bm="16"
src="https://tse3.mm.bing.net/th?id=JN.tdPCsRj4HyJzbwA%2bgXsS8g&w=217&h=142&c=7&rs=1&qlt=90&o=4&pid=1.1"
style="width:217px;height:142px;" width="217" height="142">
</a>
and here is how I tried to extract it:
String title = "dog";
String url = "https://www.bing.com/images/search?q="+title+"&FORM=HDRSC2";
try {
Document doc = Jsoup.connect(url).get();
Elements img = doc.getElementsByTag("a");
for (Element el : img) {
String src = el.absUrl("imgurl");
System.out.println(src);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Please help me! I hope you understand my problem. Waiting for answers..