您的位置:首页 > 其它

手机号归属地查询接口

2015-12-23 04:24 197 查看
string phoneNum = "手机号";
try
{
//web客户端
WebClient webclient = new WebClient();
//下载数据
string str_ = webclient.DownloadString("http://www.ip138.com:8080/search.asp?mobile=" + phoneNum + "&action=mobile");
//正则
string str_regex = "><!-- <td></td> -->.*</TD>";
//忽略大小写
Regex regex = new Regex(str_regex, RegexOptions.IgnoreCase);
//开始匹配
MatchCollection matchCollection = regex.Matches(str_);
string text = matchCollection[0].Value.Replace("><!-- <td></td> -->", "").Replace("</TD>", "");
Response.Write(text);
}
catch (Exception ex) { }

引入

using System.Text.RegularExpressions;
using System.Net;

如果

matchCollection[1]

的时候输出类型
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: