Example of the mobile phone number attribution-related information query function implemented by Python, python example

Source: Internet
Author: User

Example of the mobile phone number attribution-related information query function implemented by Python, python example

This example describes how to query information related to mobile phone number attribution in Python. We will share this with you for your reference. The details are as follows:

Query the location of the specified mobile phone number and other related information. Python implementation:

Mobile phone number file: test.txt

136932525521329662998913640810839157551066311511962273213904446048188747919531369565850013695658547159501790801557346277915217624651150184859891370652248213666519777136665151881885728752815575394501

Python implementation:

# Coding = UTF-8 # get provider information by phoneNumberfrom urllib import urlopenimport re # get html source code for urldef getPageCode (url): file = urlopen (url) text = file. read () file. close () # text = text. decode ("UTF-8") # depending on coding of source code responded return text # parse html source code to get provider informationdef parseString (src, result): pat = [] pat. append ('(? <= Geographic location: </span>). + (? = <Br/>) ') pat. append ('(? <= Card type: </span>). + (? = <Br/>) ') pat. append ('(? <= Carrier: </span>). + (? = <Br/>) ') pat. append ('(? <= Area code: </span>) \ d + (? = <Br/>) ') pat. append ('(? <= Zip code: </span>) \ d + (? = <Br/>) ') item = [] for I in range (len (pat): m = re. search (pat [I], src) if m: v = m. group (0) item. append (v) return item # get provider by phoneNumdef getProvider (phoneNum, result): url = "http://www.sjgsd.com/n? Q = % s "% phoneNum text = getPageCode (url) item = parseString (text, result) result. append (phoneNum, item) # write result to filedef writeResult (result): f = open ("result. log "," w ") for num, item in result: f. write ("% s: \ t" % num) for I in item: f. write ("% s, \ t" % I) f. write ("\ n") f. close () if _ name _ = "_ main _": result = [] for line in open ("test.txt", "r "): phoneNum = line. strip ("\ t \ r \ n") getProvider (phoneNum, result) print ("% s is finished" % phoneNum) writeResult (result)

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.