httpclient htmlparser来查询手机号相关信息

本文介绍了一个Java程序实例,通过使用HTTPClient发送POST请求到指定服务器查询手机号的相关信息,并利用HTMLParser解析返回的HTML内容。该程序演示了如何设置请求参数、执行HTTP请求及解析响应数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

httpclient htmlparser来查询手机号相关信息
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"));//直接填写想要查询的手机号码
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值