Python to implement number attribution query function

Source: Internet
Author: User
This article mainly introduces the Python implementation of the mobile phone number attribution to the relevant information query function, involving Python file read and based on the third-party interface call query information related operation skills, the need for friends can refer to the next

This paper describes the information query function of the mobile phone number attribution in Python. Share to everyone for your reference, as follows:

According to the designated mobile phone number, query its attribution and other relevant information, Python implementation:

Mobile Number file: Test.txt


1369325255213296629989136408108391575510663115119622732139044460481887479195313695658500136956585471595017908015573462779 15217624651150184859891370652248213666519777136665151881885728752815575394501

Python implementations:


# coding=utf-8# get provider information by Phonenumberfrom urllib import urlopenimport re# get HTML source code for Urlde F 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, Resul T): Pat = [] Pat.append (' (? <= attribution:</span>). + (? =<br/>) ') pat.append (' (? <= card Type:</span>). + (? = <br/>) ' Pat.append (' (? <= operator:</span>) ' (? =<br/>) ') pat.append (' (? <= area code:</span>) \d+ ( ? =<br/>) ' Pat.append (' (? <= zip:</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 Getprovi Der (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 = [] fo R Line in open ("Test.txt", "R"): Phonenum = Line.strip ("\t\r\n") Getprovider (phonenum, result) print ('%s is fini Shed "%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.