欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)的手機(jī)號(hào)歸屬地相關(guān)信息查詢功能示例

 更新時(shí)間:2017年06月08日 08:17:35   作者:JoeBlackzqq  
這篇文章主要介紹了Python實(shí)現(xiàn)的手機(jī)號(hào)歸屬地相關(guān)信息查詢功能,涉及Python文件讀取及基于第三方接口調(diào)用查詢信息的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)的手機(jī)號(hào)歸屬地相關(guān)信息查詢功能。分享給大家供大家參考,具體如下:

根據(jù)指定的手機(jī)號(hào)碼,查詢其歸屬地等相關(guān)信息,Python實(shí)現(xiàn):

手機(jī)號(hào)文件:test.txt

13693252552
13296629989
13640810839
15755106631
15119622732
13904446048
18874791953
13695658500
13695658547
15950179080
15573462779
15217624651
15018485989
13706522482
13666519777
13666515188
18857287528
15575394501

python實(shí)現(xiàn):

# coding=UTF-8
# get provider information by phoneNumber
from urllib import urlopen
import re
# get html source code for url
def 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 information
def parseString(src, result):
  pat = []
  pat.append('(?<=歸屬地:</span>).+(?=<br />)')
  pat.append('(?<=卡類型:</span>).+(?=<br />)')
  pat.append('(?<=運(yùn)營(yíng)商:</span>).+(?=<br />)')
  pat.append('(?<=區(qū)號(hào):</span>)\d+(?=<br />)')
  pat.append('(?<=郵編:</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 phoneNum
def 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 file
def 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)

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論