Skip to content Skip to sidebar Skip to footer

Jsoup Parsing Html Issue

I am new to Jsoup and am trying to parse a website, with the following html, and retrieve the value of the text input in the html below, specifically the 'value=14' which I then wa

Solution 1:

try this:

 Elements inputElems =doc.select("input");
 for (Element inputElem : inputElems){
    name = inputElem.attr("name").first();
    value = inputElem.attr("value").first();
 }

Solution 2:

I was able to finally obtain the value by using the following code:

Element pInput = doc.select("input[id=small-input]").first();
           rPts = pInput.attr("value");

This came up null initially but after I added the following code to obtain an authentication cookie which I then passed to the next web page where my data value was stored and from where I was trying to get the parse data from, it was successful.

Documentdoc1= res.parse();
            StringsessionId= res.cookie("SESSIONID");



            Documentdoc= Jsoup.connect(url)
                    .cookie("SESSIONID", sessionId)
                    .get();

Solution 3:

try this,

ElementsinputElems=doc.select("input");
Iterator<Element> linksIt = inputElems .iterator();

while (linksIt.hasNext()) {
    ElementinputElem= linksIt.next();
    Stringid= inputElem.attr("id");

    if(id.equals("small-input")){
        name = inputElem.attr("name");
        value= inputElem.attr("value");
    }
}

Post a Comment for "Jsoup Parsing Html Issue"