根目录下创建fofa.xlsx 因为直接用的fofa的导出文件 所有ip地址在E列 大伙为了方便可以自己修改一下 import xlwings as xw import requests from concurrent.futures import ThreadPoolExecutor from functools import lru_cache @lru_cache(maxsize=None) def getplace(code): try: url = r'https://opendata.baidu.com/api.php?query=' + \ str(code)+'&co=&resource_id=6006&oe=utf8' r = requests.get(url) ipcode = r.json() return ipcode["data"][0]["location"] except Exception as e: pass def process_row(ipcode): placeinfo = getplace(ipcode) return placeinfo def process_excel(): wb = xw.Book('fofa.xlsx') sheet = wb.sheets['查询结果'] info = sheet.used_range nrows = info.last_cell.row rows = sheet['E4:E' + str(nrows)] ipcodes = [row.value for row in rows] with ThreadPoolExecutor() as executor: results = executor.map(process_row, ipcodes) for row, result in zip(rows, results): sheet[row.offset(column_offset=4).address].value = result process_excel()
IP批量查询归属地-自动读取写入(超快)
最新推荐文章于 2024-03-12 22:51:50 发布