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.
Document doc1 = res.parse();
String sessionId = res.cookie("SESSIONID");
Document doc = Jsoup.connect(url)
.cookie("SESSIONID", sessionId)
.get();
Solution 3:
try this,
Elements inputElems =doc.select("input");
Iterator<Element> linksIt = inputElems .iterator();
while (linksIt.hasNext()) {
Element inputElem = linksIt.next();
String id = inputElem.attr("id");
if(id.equals("small-input")){
name = inputElem.attr("name");
value= inputElem.attr("value");
}
}
Post a Comment for "Jsoup Parsing HTML Issue"