Python,查询功能,属地
后端开发-Python教程根据指定的手机号码,查询其归属地等相关信息,Python实现:
js 取网页源码 易语言,vscode 注释显示,UBUNTU麒麟臂怎么,tomcat 用户 锁定,sqlite副作用,wordpress 服务器操作系统,discuz插件微信授权,前端框架 导入idea,爬虫保鲜,php饿汉式,网站优化seo是什么,css 网站 实例,地图网页 模板下载,飞飞赞片网模板,wordpress注册页面,成绩管理系统c语言程序源代码,discuz 程序 1.0lzw
手机号文件:test.txt源码程序,vscode替换,ubuntu服务器,tomcat 优化,sqlite js,济南网页设计公司,dz 数据库建表,新网域名主机服务器优惠券,微擎人人商城插件,前端框架排名,r 爬虫,php用,长春seo,springboot配置,h1和h2标签,网站访客统计,vb查看网页源代码,dede模板下载,帝国后台批量替换字段值怎么弄的,css3页面加载动画,多用户文件管理系统 源码,幽默笑话程序lzw
网站视频去除广告源码,ubuntu 修改成英文,tomcat数据源设置,爬虫定位ip,php 直播商城,小伙为什么做了一个seolzw
136932525521329662998913640810839157551066311511962273213904446048188747919531369565850013695658547159501790801557346277915217624651150184859891370652248213666519777136665151881885728752815575394501
python实现:
# coding=UTF-8# get provider information by phoneNumberfrom urllib import urlopenimport re# get html source code for urldef getPageCode(url): file = urlopen(url) text = file.read() file.close()# text = text.decode("utf-8") # depending on coding of source code responded return text# parse html source code to get provider informationdef parseString(src, result): pat = [] pat.append('(?<=归属地:).+(?=
)') pat.append('(?<=卡类型:).+(?=
)') pat.append('(?<=运营商:).+(?=
)') pat.append('(?<=区号:)\d+(?=
)') pat.append('(?<=邮编:)\d+(?=
)') item = [] for i in range(len(pat)): m = re.search(pat[i], src) if m: v = m.group(0) item.append(v) return item# get provider by phoneNumdef getProvider(phoneNum, result): url = "http://www.sjgsd.com/n/?q=%s" %phoneNum text = getPageCode(url) item = parseString(text, result) result.append((phoneNum, item))# write result to filedef writeResult(result): f = open("result.log", "w") for num, item in result: f.write("%s:\t" %num) for i in item: f.write("%s,\t" %i) f.write("\n") f.close()if __name__ == "__main__": result = [] for line in open("test.txt", "r"): phoneNum = line.strip(" \t\r\n") getProvider(phoneNum, result) print("%s is finished" %phoneNum) writeResult(result)