Python批量获取并保存⼿机号归属地和运营商的⽰例从Excel读取⼀组⼿机号码,批量查询该⼿机号码的运营商和归属地,并将其追加到该记录的末尾。
import requests
import json
import xlrd
py import copy
host = 'cx.shouji.360/phonearea.php'
# excel⽂件路径
file_path = "F:\\temp.xlsx"
# 新⽂件路径
new_file_path = "F:\\temp(含归属地+运营商).xlsx"
def query(phone_no):
resp = (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 = _sheet(0)
python能在手机上运行吗
rows = ws
cols = ls
print("总⾏数:" + str(rows))
print("总列数:" + str(cols))
for row in range(rows):
print("row --> " + str(row + 1))
for col in range(cols):
cel_val = ll(row, col).value
print(cel_val)
new_worksheet.write(row, col, cel_val)
if row > 0:
# ⼿机号,在第⼀⾏之后的第⼆列
phone_no = ll(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批量获取并保存⼿机号的资料请关注其它相关⽂章!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。