Python cell phone number attribution to query code

Source: Internet
Author: User
A simple example, previously written in Dephi, was recently implemented in Python using the Delphi control to write the interface program, so hot write a similar query scheme.

This example is through the www.ip138.com this website to query, here need a few knowledge points, is to use Python Simulation Web page submit data, get data return information, and the return of HTML information to parse, simulate HTTP commit, Python comes with a urllib and Urllib2 library, which is quite handy, just wondering why it's easier to combine two libraries into one. Then there is the form, and the form is DXVCL by a Python module I wrote earlier, which is a library of modules that can invoke the Delphi interface control in Python. Here is the code, quite simple!

#-*-coding:gb2312-*-import urllib,urllib2,htmlparserfrom dxvcl import*class myparser (HTMLParser.HTMLParser):d EF 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 = Falsedef handle_data (self, Data): If Self._isintd:self._retdata.append (data) class MainForm (Form):d ef__init__ (Self,owner): self. Caption = ' Query phone attribution ' self. Position =5self. BorderStyle =3self. Width =303self. Height =375SELF.LBL = Label (self) self.lbl.SetProps (Parent = self,caption = ' mobile number ') 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 = ' query ') self. Button1.setbounds (204,1,75,25) self. Button1.onclick = self. Button1clickself.memo1 = Memo (self) self. Memo1.parent = selfself. 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 = ' Query phone attribution ' F = mainform ( application) F.show () Application.Run () if__name__== ' __main__ ': Main ()

After running the interface

The above is a small series to introduce you to the Python mobile phone number attribution Query code, I hope to help you!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.