httpclient htmlparser来查询手机号相关信息
http://htmlparser.com.cn/post/20090816119.html
http://htmlparser.com.cn/post/20090816119.html
public class GetMobile {
/**
* @author rrong_m 51jsp.cn
* @throws IOException
* @throws HttpException
* @throws IOException
* @throws HttpException
* @throws ParserException
*/
public static String getPostString(String mobile) throws HttpException, IOException//发送数据51jsp.cn
{
HttpClient hc=new HttpClient();
PostMethod pm=new PostMethod("http://www.ip138.com:8080/search.asp");
hc.getParams().setContentCharset("gb2312");
pm.addParameter("mobile",mobile);
pm.addParameter("action","mobile");
hc.executeMethod(pm);
return pm.getResponseBodyAsString();
}
public static void getMobileInfor(String poststring) throws ParserException
{
Parser parser=new Parser(poststring);
NodeList nodelist=null;
NodeFilter filter=new HasAttributeFilter("class","tdc2");
nodelist=parser.extractAllNodesThatMatch(filter);
for(int i=0;i<nodelist.size();i++)
{
System.out.println(nodelist.elementAt(i).toPlainTextString().replace(" ",""));
}
}
public static void main(String[] args) throws HttpException, IOException, ParserException {
getMobileInfor(getPostString("1380001"));//直接填写想要查询的手机号码
}
}
本文介绍了一个Java程序实例,通过使用HTTPClient发送POST请求到指定服务器查询手机号的相关信息,并利用HTMLParser解析返回的HTML内容。该程序演示了如何设置请求参数、执行HTTP请求及解析响应数据。

被折叠的 条评论
为什么被折叠?



