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-*-
ImportUrllib,urllib2,htmlparser
fromDXVCLImport*
classMyparser (Htmlparser.htmlparser):
defReset (self):
Self._isintd=False
Self._retdata= []
HTMLParser.HTMLParser.reset (self)
defHandle_starttag (Self,tag,attris):
Self._isintd=Tag=='TD'
defHandle_endtag (Self,tag):
ifSelf._isintd:
Self._isintd=False
defHandle_data (self,data):
ifSelf._isintd:
Self._retdata.append (data)
classMainForm (Form):
def__init__(Self,owner):
Self. Caption='Find your phone's place of ownership'
Self. Position=5
Self. BorderStyle=3
Self. Width=303
Self. Height=375
SELF.LBL=Label (self)
Self.lbl.SetProps (Parent=self,caption='Mobile phone number')
Self.lbl.SetBounds ( -,8, -, -)
Self. Edtphone=Edit (self)
Self. Edtphone.setprops (Parent=Self,text="')
Self. Edtphone.setbounds ( the,3,121, +)
Self. Button1=Button (self)
Self. Button1.setprops (Parent=self,caption='Enquiry')
Self. Button1.setbounds (204,1, the, -)
Self. Button1.onclick=Self . Button1Click
Self. Memo1=Memo (self)
Self. Memo1.parent=Self
Self. Memo1.setbounds ( -, +,263,297)
defButton1Click (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 ()
forDatainchMy._retdata:
Self. MEMO1.LINES.ADD (data)
defMain ():
Freeconsole ()
Application.initialize ()
Application.title='Find phone ownership'
F=mainform (application)
F.show ()
Application.Run ()
if__name__=='__main__':
Main ()
After running the interface
Use Python to find your mobile phone number attribution