Reputation: 152
I am using Jsoup in my application and I am attempting to parse information from an a few input tags in order to add them to a url and post data automatically.
The portion of HTML I am attempting to parse is as follow:
<div class='theDivClass'>
<form method="post" id="handlePurchase" name="makePurchase" action="/shop.php">
<input type="hidden" name="ProductCode" value="A1223MN" />
<input type="hidden" name="SystemVersion" value="3" >
<input type="hidden" name="ProductClass" value="BOOK" />
</form>
</div>
The desired output would be
x = A1223MN
y = 3
z = BOOK
I am halfway familiar with JSOUP in the sense that I am able to parse out text, images, and urls but for some reason this is not clicking for me.
Any help would be greatly appreciated.
Upvotes: 1
Views: 3840
Reputation: 4099
There's another way I found:
FormElement f = (FormElement) doc.select("form#handlePurchase").first();
System.out.println(f.formData());
Result:
[ProductCode=A1223MN, SystemVersion=3, ProductClass=BOOK]
Upvotes: 1
Reputation: 149
You should be able to use this:
Elements hidden = doc.select("input[type=hidden]");
And then just pull the attr values from each element in hidden
. I've just tried it and it seems to work as expected.
For completeness:
Map<String,String> hiddenList = new HashMap<String, String>();
Elements hidden = doc.select("input[type=hidden]");
for (Element el1 : hidden){
hiddenList.put(el1.attr("name"),el1.attr("value");
}
Will give you a Map of all hidden input fields in the document.
Upvotes: 7
Reputation: 152
Closing this question as it appears from all of the research I have done, you cannot pull data from "hidden" input types.
Upvotes: -2
Reputation: 15390
Element.select("input[name=productCode]").attr("value");
Element.select("input[name=SystemVersion]").attr("value");
Element.select("input[name=ProductClass]").attr("value");
Upvotes: 1