[英]Get specific string value from my response data
I am getting response data from my java code, I hit URL as follows, 我从Java代码中获取响应数据,按如下所示访问URL,
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... 我正在将html数据作为字符串值...
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. 然后,您可以从doc对象中找到您的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.