手机号码归属地批量查询功能
朋友有这么一个需求:他从网上查询到自己的通话记录,然后他想把所有北京的号码调出来,可是查到的号码不带归属地,只能一个个的查询,很麻烦,于是我写了一段javascript代码,可以批量查询,代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>手机号码归属地批量查询</title>
</head>
<body>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script language="javascript">
var timeout = 5;//每条记录查询延时时间,单位:秒
var strContent = "";
var strArray = "";
function getInfo()
{
strContent = document.getElementById("strContent").value;
strArray = strContent.split(navigator.appName=="Netscape"?"\n":"\r\n");
$("#contentDiv").html("");
getCity(0);
}
function getCity(i)
{
var num = strArray[i].replace(new RegExp(" ","g"),"").replace(new RegExp("\t","g"),"");
$.ajax({
type: "POST",
dataType:"jsonp",
url: "http://api.showji.com/Locating/20120413.aspx",
data: "m=" + num + "&output=json",
jsonpCallback:"querycallback",
success: function(msg){
$("#contentDiv").html($("#contentDiv").html() + "号码:" + num + " 城市:" + msg.City + "<br />");
i++;
if(i < strArray.length) {
setTimeout("getCity(" + i + ")", timeout * 1000);
}
}
});
}
</script>
<form id="form1" name="form1" method="post" action="">
<p>请输入手机号码(多条记录用回车换行):<br />
<textarea name="strContent" id="strContent" cols="80" rows="12"></textarea>
<input type="button" name="Button" value="查询号码所在城市" onclick="getInfo()" />
</p>
<p id="contentDiv"> </p>
</form>
</body>
</html>
代码打包下载:https://files.cnblogs.com/modou/20120420.rar
注意内容:
1、代码用到了jquery,需要把jquery的对应代码添加进来
2、我使用的这个网址:http://api.showji.com/Locating/20120413.aspx 抓取的手机归属地,如果该网址发生变化,可以再重新到http://www.showji.com/ 获取相关网址,这个网址可以在该网站查询的时候,开启Fiddler2工具监控到。
3、可能是http://www.showji.com/ 做了限制,在一定时间内查询的次数过多就查询不到对应的结果了,我把查询时间的间隔设为5秒钟,如果号码比较多,等待的时间会比较长一些

浙公网安备 33010602011771号