Python代码通过前三+后二生成地区所有手机号码

生成位置:运行目录下path文件夹。

代码:

#导入模块
import numpy
import re
import requests
import time

#添加参数
print('叮!请完善相关参数.模式1代表将所有号码写入一个vcf一次性导入.模式二代表将通过号段进行分割')
seed0 = input('模式(1/2)')
seed1 = input('头三位:')
seed2 = input('城市(拼音):')
seed3 = input('尾2位:')

#计时
S = time.perf_counter()

#获取号段
modify = seed1 + '/' + seed2 + '.htm'
url = 'https://m.jihaoba.com/haoduan/' + modify
headers = {'User-Agent' : 'Mozilla/5.0 (Linux; U; Android 10; zh-Hans-CN; HLK-AL00 Build/HONORHLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.108 Quark/5.6.6.211 Mobile Safari/537.36'}
seedling = requests.get(url=url,headers=headers).text
ex = '(\d{7})号段'
Mature = re.findall(ex,seedling,re.S)
matrix0 = numpy.array(Mature)
matrix = matrix0.astype(int)

#运算
matrix2 = matrix * 100
list0 = matrix2.tolist()
listK = []
for i in list0:
    segment = numpy.arange(i,i+100,dtype=numpy.int64)
    fruit = segment * 100 + int(seed3)
    listK.append(fruit.tolist())

#数据处理
if int(seed0)==2:
    for x in range(len(listK)):
        for n in listK[x]:
            s = 'BEGIN:VCARD\n'+'N;CHARSET=UTF-8:'+str(n)+'\n'+'FN;CHARSET=UTF-8:'+str(n)+'\n' +'TEL;TYPE=CELL:'+str(n)+'\n'+'END:VCARD'+'\n'
            with open('./path/'+str(x)+'.vcf','a',)as f:
                f.write(s)
else:
    for x in range(len(listK)):
        for n in listK[x]:
            s = 'BEGIN:VCARD\n'+'N;CHARSET=UTF-8:'+str(n)+'\n'+'FN;CHARSET=UTF-8:'+str(n)+'\n' +'TEL;TYPE=CELL:'+str(n)+'\n'+'END:VCARD'+'\n'
            with open('./path/'+'number.vcf','a',)as f:
                f.write(s)

#计时
E = time.perf_counter()
dur = E-S

#输出成果
print('共生成号码:'+'\n'+str(len(listK)*100))
print('耗时:'+'\n'+str(dur))

运行截图: