I would like to parse an html source string to find a specific tag in Java -
so have following html source:
<form action='http://example.com' method='get'> <p>some example text here.</p> <input type='text' class='is-input' id='agent_name' name='devicename' placeholder='device name'> <input type='hidden' name='p' value='firefox'> <input type='hidden' name='email' value='example@example.com'> <input type='hidden' name='k' value='citbk236gyd56oiy0fhk6lpuo9nt61va'> <p><input type='submit' class='btn-blue' style='margin-top:15px;' value='install'></p> </form>
unfortunately html source saved string. parse using jsoup. , obtain following string: <input type='hidden' name='k' value='citbk236gyd56oiy0fhk6lpuo9nt61va'>
or better yet, grab following value: citbk236gyd56oiy0fhk6lpuo9nt61va
the problem i'm running that:
a) value: citbk236gyd56oiy0fhk6lpuo9nt61va
consistently changing cannot entire html tag.
so, looking better way this. here have not seem working:
//tried use thing, java angry reason jsoup.parse(mystring); // used instead. org.jsoup.nodes.document doc = jsoup.parse(mystring); // in case tried select entire tag. elements elements = doc.select("<input name=\"k\" value=\"citbkdxjtfd56oiy0fhk6luu8owt61va\" type=\"hidden\">"); //yeah not seem work. assume it's not string anymorebut document. not sure if //would attempt print anyway. system.out.println(elements);
so guess can't use select, if work. not sure how place select part of tag , place new string.
you can try way
document doc = jsoup.parse(mystring); elements elements = doc.select("input[name=k]"); system.out.println(elements.attr("value"));
output:
citbk236gyd56oiy0fhk6lpuo9nt61va
Comments
Post a Comment