从Excel读取一组手机号码,批量查询该手机号码的运营商和归属地,并将其追加到该记录的末尾。SAb免费资源网
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("总行数: