I am getting response data from my java code, I hit URL as follows,
String url = "http://www.google.com/search?q=mkyong";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
I am getting the html data as string values...
I want to get a hidden value from this response data.
<input type="hidden" name="HREF.DUMMY.MENSYS.1"
value="-X-tB--3TF8LlA02j-LKYRAT75rwYwwchuvSyZ9vWVwQ0"
id="url" />
How to get this value?
You can,
Just use the following code with your response,
Document doc = Jsoup.connect(response.toString());
Element el= doc.select("type[hidden]");
Streing val = el.getAttr("value");
Then you can find your element from the doc object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.