I have never been interested in parsing sites before, but now I need to parse the VK page. I wrote such a code, which, as I understand it, should output Online. But he takes nothing at all. What is the problem? No errors
public static void main(String[] args) throws IOException { Document doc = Jsoup.connect("https://vk.com/id94283688").get(); List<String> strings = new ArrayList<>(); Elements h4Elements = doc.getElementsByAttributeValue("class", "profile_online"); h4Elements.forEach(h4Element -> { Element element = h4Element.child(0); strings.add(element.text()); }); for (String s :strings) { System.out.println(s); } }
Here is this element:
<h4 class="profile_online"><div id="profile_online_lv">Online<b class="mob_onl profile_mob_onl unshown" id="profile_mobile_online" onmouseover="mobileOnlineTip(this, {mid: cur.oid, right: 1})" onclick="mobilePromo(); "></b></div> </h4>
PS: I am new and do not have much knowledge in programming
doc
, what is inh4Elements
? Obviously, if the code prints nothing, thenh4Elements
contains no elements. - andreychaonline
. - Roman