import json import pandas as pd import package_info as obj import pymongo myclient = pymongo.MongoClient('localhost', 27017) # 连接MongoDB db = myclient['temp_user_info'] DataYuan = db['qqandtel'] DataResult = db["result"] # 将这一千条数据添加到Mongodb # result = pd.read_excel("第一批.xlsx",sheet_name="Sheet1",header=0)["QQ号"] # print(result) # for i in result: # DataYuan.insert_one({"QQ号":i}) # 数据添加完毕,请勿重复执行,因此上述代码注释掉 # 从MongoDB读取数据 now = 0 for i in DataYuan.find(): count = DataYuan.find().count() qq = (i["QQ号"]) result = obj.API_FromQQtoALl(qq) code = result["code"] data = result["data"] if code==-1: # DataYuan.insert({"QQ号":qq}) # 没有删除,因此也无需添加 pass else: DataResult.insert_one({"QQ":data['qq'],"手机号码":data['tel'],'手机归属地':data['address'],'微博ID':data['id']}) DataYuan.delete_one({"QQ号":qq}) now=now+1 print(str(now)+"/"+str(count)) # result = pd.read_excel("第一批.xlsx",0) # datas = result["QQ号"].tolist() # # print(datas) # # for i in range(0,len(result['QQ号'])): # result_all=[] # i = 0 # for qq in datas: # result = obj.API_FromQQtoALl(qq) # code = result["code"] # data = result["data"] # if code==-1: # datas.append(qq) # print("[" + str(i) + "]", qq, "获取失败") # else: # result_all.append({"QQ":data['qq'],"手机号码":data['tel'],'手机归属地':data['address'],'微博ID':data['id']}) # print("[" + str(i) + "]", qq, "获取完成") # i=i+1 # # # print(result_all) # td = pd.DataFrame(columns=["QQ","手机号码",'手机归属地','微博ID'],data=result_all) # # td = pd.read_json(result_all) # # print(td) # td.to_excel('result.xlsx',encoding='utf-8') # print("完毕!") # # # #