日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3 reqeusts后写入excel

發布時間:2025/7/25 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3 reqeusts后写入excel 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用python通過手機號批量辨別運營商并寫入excel

初始文件:

具體代碼:

#coding=utf-8 import requests import re import xlrd import xlwtread_path = 'xxx.xlsx' #你的初始文件 write_path='xxx.xls' #你的生成文件# 設置手機號和運營商列表 phonelist = ['手機號'] yyslist = ['運營商'] # 讀取excel, def read_excel(read_path):# 打開文件filename = xlrd.open_workbook(read_path)# 獲取當前文檔的表(得到的是sheet的個數,一個整數)sheets=filename.nsheets# 通過sheet索引獲得sheet對象sheet = filename.sheet_by_index(0)# 獲取行數nrows = sheet.nrowsprint(nrows)# 獲取列數ncols = sheet.ncolsprint(ncols)# 獲取第2行,第2列數據(調取接口,獲取手機號的運營商信息,并存在yyslist)cell_value = sheet.cell_value(1, 1)print(type(cell_value))# print ("https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel="+sheet.cell_value(1,0))# 獲取第2行以后的數據(第一列)#獲取每個手機號獲取信息,并用正則從返回中獲取catNamefor i in range(1, nrows):ur = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=" + str(int(sheet.cell_value(i, 0)))print(ur)response = requests.get(ur)response.enconding = 'utf-8'xinxi = response.textres = re.findall("catName:'(.*?)',", xinxi, re.M | re.S | re.U)print(res)yyslist.append(res)phonelist.append(int(sheet.cell_value(i, 0)))print(yyslist)#檢查運營商信息print(phonelist)#檢查手機號 #寫入新的excel def write_excel(write_path):# 創建工作簿workbook = xlwt.Workbook(encoding='utf-8')# 創建sheetdata_sheet = workbook.add_sheet('demo')# 生成第一列和第二列for i in range(len(yyslist)):data_sheet.write(i, 0, phonelist[i])data_sheet.write(i, 1, yyslist[i])# 保存文件# workbook.save('demo.xls')workbook.save(write_path)# book2 = copy(filename)# sheet = book2.get_sheet(0)# for i in range(1,9):# sheet.write(i, 1, yyslist[i-1])## book2.save('D:\saaa.xlsx') read_excel(read_path) write_excel(write_path)

?

轉載請備注“文章轉載來自博客園-輸是誰”

?

轉載于:https://www.cnblogs.com/xinguichun/p/10993855.html

總結

以上是生活随笔為你收集整理的python3 reqeusts后写入excel的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。