With JSoup, I want to get the value "href" (I need to get the value "11"). How to do it?

<!--?xml version="1.0" encoding="utf-8"?--><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" class="page page_js_no "> <body id="dik" class="page__body _hover dik_stickers_hints_support_no opera_mini_no dik_al_no"> <div class="layout"> <div class="layout__body " id="dik_wrap"> <div class="layout__basis" id="m"> <div class="basis"> <div class="basis__header mhead" id="mhead"> <a href="/id11" accesskey="*" class="hb_wrap mhb_home mhb_dikhome"> 

    1 answer 1

    You just need to get the first element by the name of its class and take its attribute like this:

     Document doc = Jsoup.parse(html); String href = doc.getElementsByClass("hb_wrap mhb_home mhb_dikhome").get(0).attr("href"); 
    • Error: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 - Vladimir
    • one
      It turned out like this: String href = doc.getElementsByClass ("hb_wrap"). Get (0) .attr ("href"); Removed spaces. - Vladimir