How do I make an Array from jSoup Elements? (java)
How do I get the values in a piece of Html (values="valueIWant"), and have them in an Array ? I tried the following, but that didn't work:
HttpEntity entity5 = response5.getEntity();
String defaultString = EntityUtils.toString(entity5);
Document defaultDoc = Jsoup.parse(defaultString);
Elements values = defaultDoc.getElementsByAttribute("value"); //DropDownList Values
String s[] = {""};
for(int a=0; a<values.size(); a++){
s[a] = values.开发者_JS百科get(a).toString();
}
return s;
So anyone got an answer? thanks. (Btw, i use Jsoup)
First of all: is your HTML parsed correctly? Can you provide the contents of defaultString
? Is defaultDoc
valid is there a problem with file encodings perhaps?
Assuming getElementsByAttribute
actually returns some objects —note that you have a typo, value
instead of values
— you're currently populating the array with the descriptions of all Element
-objects, not the values of the attribute. Try something like the following:
int i = 0;
String s[] = new String[values.size()];
for(Element el : values){
s[i++] = el.attr("values");
}
精彩评论