How to get a value from html element in Android? -


how can "h4siaaa"?

string out='<input type="hidden" name="javax.faces.viewstate" id="javax.faces.viewstate" value="h4siaaa"  autocomplete="off" />'; 

the best way stuff use regular expressions.

a simple example matching problem:

string out= "<input type=\"hidden\" name=\"javax.faces.viewstate\" id=\"javax.faces.viewstate\" value=\"h4siaaa\"  autocomplete=\"off\" />"; pattern pattern = pattern.compile(".*(value=\"(\\w*)\").*", pattern.case_insensitive); matcher matcher = pattern.matcher(out);  if (matcher.matches()) {   system.out.println(matcher.group(2)); } 

this working 1 line inputs 1 accourance of "value=".

what do?

  1. it prepares regular expression matcher matches whole string, group "value" attribute , second group value of attribute "value"

  2. it creates matcher using pattern , given string "out"

  3. if matcher matches prints out group content 2, attributes value

the benefit of using regular expression can make expression ignoring useless content regardless , concentrat on extract want. example usefull 1 line input 1 value attribute. when want parse hole html pages, have extend needs.

regex doc: https://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html place test regex: http://regexr.com/

have fun!


Comments