黑松山资源网 Design By www.paidiu.com
简单的一个例子,是以前用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手机号码归属地查询代码,希望对大家有所帮助!
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮什么时候开始 s14瑞士轮开始时间介绍
- 晨报|《使命召唤21》全球发布预告 《异形:隔离》续作官宣开发中
- 隐形女联动毁灭博士?杰西卡·阿尔巴与小唐尼晒合影
- 《博德之门3》7号补丁发布后:Mod下载量达到2200万次!
- 徐璨宾《井底的蚯蚓》[FLAC/分轨][218.37MB]
- 王冰冰《Vaga Luna 月球漫游》[320K/MP3][62.76MB]
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[320K/MP3][59.79MB]
- 群星.1993-飞图合唱歌曲精丫飞图】【WAV+CUE】
- 王霏霏.2024-TOOOOO.BUSY(EP)【SNMUSIC】【FLAC分轨】
- 张宇.2016-好男人的情歌NEWXRCD【金牌大风】【WAV+CUE】
- 《食戟之灵》小林龙胆兔女郎比基尼版模型即将发售
- 重大里程碑!九号电动第500万台智能两轮电动车正式下线
- TGA主持人发文祝贺《暗喻幻想》 国外网友:提名稳了?
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号81~序号90)
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号91~序号100)