您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python手机号码归属地查询示例代码

2024/2/26 19:22:53发布12次查看
简单的一个例子,是以前用dephi写的,前不久刚实现了一个在python中使用delphi控件来编写界面程序,于是趁热写一个类似的的查询方案。
本实例是通过www.ip138.com这个网站来查询的,这里需要的几个知识点,就是用python模拟网页提交数据,获得数据返回信息,以及对返回的html信息进行解析,模拟http提交,python自带有一个urllib和urllib2这两个库,相当方便,只是奇怪,为什么不将两个库合并成一个,这样来的更方便。然后就是窗体了,窗体还是用我之前写的一个python模块dxvcl,就是可以在python中调用delphi界面控件的一个模块库。下面就贴上代码,相当简单的!
#-*-coding: gb2312 -*- import urllib,urllib2,htmlparser from dxvcl import* class myparser(htmlparser.htmlparser): def reset(self): self._isintd = false self._retdata = [] htmlparser.htmlparser.reset(self) def handle_starttag(self,tag,attris): self._isintd = tag =='td' def handle_endtag(self,tag): if self._isintd: self._isintd = false def handle_data(self,data): if self._isintd: self._retdata.append(data) class mainform(form): def__init__(self,owner): self.caption ='查询手机归属地' self.position =5 self.borderstyle =3 self.width =303 self.height =375 self.lbl = label(self) self.lbl.setprops(parent = self,caption ='手机号码') self.lbl.setbounds(16,8,60,13) self.edtphone = edit(self) self.edtphone.setprops(parent = self,text ='') self.edtphone.setbounds(77,3,121,21) self.button1 = button(self) self.button1.setprops(parent = self,caption ='查询') self.button1.setbounds(204,1,75,25) self.button1.onclick = self.button1click self.memo1 = memo(self) self.memo1.parent = self self.memo1.setbounds(16,32,263,297) def button1click(self,sender): postdata = urllib.urlencode([('action','mobile'),('mobile',self.edtphone.text)]) req = urllib2.request('http://www.ip138.com:8080/search.asp') fd = urllib2.urlopen(req,postdata) h = fd.read() my = myparser() my.feed(h) self.memo1.lines.clear() for data in my._retdata: self.memo1.lines.add(data) def main(): freeconsole() application.initialize() application.title ='查询手机归属' f = mainform(application) f.show() application.run() if__name__=='__main__': main()
运行之后的界面
以上所述是小编给大家介绍的python手机号码归属地查询代码,希望对大家有所帮助!
更多python手机号码归属地查询示例代码。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product