这里就按照查号码页面,返回的是一个html页面,从页面中获取带到需要的信息,
有时候会出现乱码,
EntityUtils.toString(entity, "gb2312")
小陷阱---设置的编码格式要按照,返回的页面头信息中的编码格式设置,
如果设置了utf-8就会出现乱码
try {
HttpClient httpClient = new DefaultHttpClient();
String url = "http://wap.ip138.com:8080/search.asp?mobile=18862165079&action=mobile";
HttpGet get = new HttpGet(url);
HttpResponse response = null;
response = httpClient.execute(get);
HttpEntity entity = response.getEntity();
String str = EntityUtils.toString(entity, "gb2312");
Document doc = Jsoup.parse(str);
Elements trs = doc.select("table").get(1).select("tr");
for (int i = 0; i < trs.size(); i++) {
Elements tds = trs.get(i).select("td");
for (int j = 0; j < tds.size(); j++) {
String text = tds.get(j).text();
System.out.println(text);
}
}
}catch (Exception e){
e.printStackTrace();
}
java 模拟页面表单提交,并处理返回的数据
转载链接
https://blog.csdn.net/weixin_41541415/article/details/80278653