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)