手机号归属地批量查询(接上)

终于在上期作品后,找到了一个接口,我也是十分nb的分享一下,跑1000个号只用20秒左右,wc直接震惊到我,对比上期得用20分钟,质的飞跃,因为代码比较粗糙,多进程搞了一大堆,但我还是无偿分享

代码如下:

import requests
from lxml import etree
import multiprocessing

with open('result.txt', 'w') as file:
    file.truncate()

def Phone_query(phone_num):
    url = 'https://www.shoujihao.com/jxcs/jx-'+str(phone_num)+'/'
    r = requests.get(url)
    r.encoding = 'utf-8'
    num = r.text
    num1 = etree.HTML(num)
    num2 = num1.xpath('/html/body/div[6]/div[3]/div[2]/table/tbody/tr[1]/td[2]/text()')
    for num3 in num2:
        print(num3)
    b = '河南' in num3
    if str(b) == 'True':
        with open('result.txt','a',encoding='utf-8') as file:
            file.write(str(phone_num) + '\n')
        print('True')

def run1():
    with open('phone_num1.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run2():
    with open('phone_num2.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run3():
    with open('phone_num3.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run4():
    with open('phone_num4.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run5():
    with open('phone_num5.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run6():
    with open('phone_num6.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run7():
    with open('phone_num7.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run8():
    with open('phone_num8.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run9():
    with open('phone_num9.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

def run10():
    with open('phone_num10.txt','r') as file:
        a1 = file.readlines()
        for b in a1:
            b1 = b.strip("\n").split()
            for b2 in b1:
                Phone_query(b2)

if __name__ == '__main__':
    x1 = multiprocessing.Process(target=run1)
    x2 = multiprocessing.Process(target=run2)
    x3 = multiprocessing.Process(target=run3)
    x4 = multiprocessing.Process(target=run4)
    x5 = multiprocessing.Process(target=run5)
    x6 = multiprocessing.Process(target=run6)
    x7 = multiprocessing.Process(target=run7)
    x8 = multiprocessing.Process(target=run8)
    x9 = multiprocessing.Process(target=run9)
    x10 = multiprocessing.Process(target=run10)
    x1.start()
    x2.start()
    x3.start()
    x4.start()
    x5.start()
    x6.start()
    x7.start()
    x8.start()
    x9.start()
    x10.start()
    x1.join()
    x2.join()
    x3.join()
    x4.join()
    x5.join()
    x6.join()
    x7.join()
    x8.join()
    x9.join()
    x10.join()


这回直接是终极版了,需把1000个号码拆分成10份,依此类推

该文章由本人原创,感谢大家的支持!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值