Python mobile phone number example code

Source: Internet
Author: User
This article mainly introduces Python mobile phone numbers used to query code information. For more information, see Dephi, not long ago, I just implemented an interface program using the Delphi control in Python, so I wrote a similar query scheme.

This instance is queried through www.ip138.com. the knowledge point here is to use Python to simulate web pages to submit data, obtain data return information, and parse the returned Html information, simulate Http submission. Python comes with a urllib and urllib2 libraries, which is quite convenient. it's just a strange question: why not merge the two libraries into one, which makes it more convenient. Then there is the form. The form is still a Python module DxVcl that I wrote earlier. it is a module library that can call the Delphi interface control in Python. Paste the code below, which is quite simple!

#-*-Coding: gb2312-*-import urllib, urllib2, HTMLParserfrom 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 = Falsedef handle_data (self, data): if self. _ isInTd: self. _ retdata. append (data) class MainForm (Form): def _ init _ (self, Owner): self. caption = 'query the phone locations 'self. position = 5self. borderStyle = 3self. width = 303self. height = 375self. lbl = Label (self) self. lbl. setProps (Parent = self, Caption = 'mobile phone 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 (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 mobile phone attributions 'F = MainForm (Application) f. show () Application. run () if _ name __= = '_ main _': main ()

Interface after running

The above is a small series of Python mobile phone numbers for you to query the code, I hope to help you!

For more Python mobile phone numbers, please refer to the PHP Chinese network for more articles about the sample code!

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.