How to get id from html Objects with Jsoup - Java -
i want find id of html objects jsoup.
<object id="gamediv" </object>
i tried:
string startingurl = "http://www.example.com"; try { doc = jsoup.connect(startingurl) .useragent("mozilla/5.0 (windows nt 6.1; win64; x64; rv:25.0) gecko/20100101 firefox/25.0") .referrer("http://www.google.com") .timeout(1000*5) //it's in milliseconds, means 5 seconds. .get(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } elements = doc.select("object"); (element elem : get){ if (get.attr("id") != null){ system.out.println(get.attr("id")); } }
but nothing happens. please?
first of can reduce code simple.
for (element elem : doc.select("object[id]")) { system.out.println(elem.attr("id")); }
secondly if doc
doesn't contain object
looking for, means wasn't sent server. there may few reasons ones
- incorrect user agent header,
- this html code generated browser via javascript.
first case doesn't seem apply here, in case of dynamic content should use other library since jsoup parser, not browser emulator. if looking more powerful tool take web drivers selenium.
Comments
Post a Comment