Python批量获取并保存手机号归属地和运营商的示例
#代码知识 发布时间: 2026-01-12
从Excel读取一组手机号码,批量查询该手机号码的运营商和归属地,并将其追加到该记录的末尾。
import requests
import json
import xlrd
from xlutils.copy import copy
host = 'https://cx.shouji.360.cn/phonearea.php'
# excel文件路径
file_path = "F:\\temp.xlsx"
# 新文件路径
new_file_path = "F:\\temp(含归属地+运营商).xlsx"
def query(phone_no):
resp = requests.get(host, {'number': phone_no}).content.decode('utf-8')
js = json.loads(resp)
print(js)
return js['data']
def load_excel(path):
# 打开文件
data = xlrd.open_workbook(path)
# 打开第一个sheet
table = data.sheet_by_index(0)
new_workbook = copy(data)
new_worksheet = new_workbook.get_sheet(0)
rows = table.nrows
cols = table.ncols
print("总行数:" + str(rows))
print("总列数:" + str(cols))
for row in range(rows):
print("row --> " + str(row + 1))
for col in range(cols):
cel_val = table.cell(row, col).value
print(cel_val)
new_worksheet.write(row, col, cel_val)
if row > 0:
# 手机号,在第一行之后的第二列
phone_no = table.cell(row, 1).value
js = query(phone_no)
new_worksheet.write(row, cols + 1, js['province'] + js['city'])
new_worksheet.write(row, cols + 2, js['sp'])
else:
new_worksheet.write(row, cols + 1, "归属地")
new_worksheet.write(row, cols + 2, "运营商")
print('\r\n')
new_workbook.save(new_file_path)
if __name__ == '__main__':
load_excel(file_path)
以上就是Python批量获取并保存手机号归属地和运营商的示例的详细内容,更多关于Python批量获取并保存手机号的资料请关注其它相关文章!
代码知识SEO上一篇 : java 枚举enum的用法(与在switch中的用法)
下一篇 : Python类绑定方法及非绑定方法实例解析
-
SEO外包最佳选择国内专业的白帽SEO机构,熟知搜索算法,各行业企业站优化策略!
SEO公司
-
可定制SEO优化套餐基于整站优化与品牌搜索展现,定制个性化营销推广方案!
SEO套餐
-
SEO入门教程多年积累SEO实战案例,从新手到专家,从入门到精通,海量的SEO学习资料!
SEO教程
-
SEO项目资源高质量SEO项目资源,稀缺性外链,优质文案代写,老域名提权,云主机相关配置折扣!
SEO资源
-
SEO快速建站快速搭建符合搜索引擎友好的企业网站,协助备案,域名选择,服务器配置等相关服务!
SEO建站
-
快速搜索引擎优化建议没有任何SEO机构,可以承诺搜索引擎排名的具体位置,如果有,那么请您多注意!专业的SEO机构,一般情况下只能确保目标关键词进入到首页或者前几页,如果您有相关问题,欢迎咨询!