当前位置: 首页 > wzjs >正文

徐州企业制作网站国外引擎搜索

徐州企业制作网站,国外引擎搜索,医院网站建设选哪家,小程序开发基于python抽取目录下所有“jsonl”格式文件。遍历文件内某个字段进行抽取并合并。 import os import json import time from tqdm import tqdm # 需要先安装:pip install tqdmdef process_files():# 设置目录路径dir_path r"D:\daku\关键词识别\1623-00000…

基于python抽取目录下所有“jsonl”格式文件。遍历文件内某个字段进行抽取并合并。

import os
import json
import time
from tqdm import tqdm  # 需要先安装:pip install tqdmdef process_files():# 设置目录路径dir_path = r"D:\daku\关键词识别\1623-0000001\zh"# 获取并排序文件列表file_list = sorted([f for f in os.listdir(dir_path) if f.lower().endswith('.jsonl')],key=lambda x: os.path.getsize(os.path.join(dir_path, x)),reverse=True)  # 按文件大小降序排列# 进度统计total_files = len(file_list)processed_files = 0total_lines = sum(1 for f in file_list for _ in open(os.path.join(dir_path, f), 'r', encoding='utf-8'))processed_lines = 0start_time = time.time()# 输出文件设置output_file = os.path.join(dir_path, "combined_contents.txt")with open(output_file, "w", encoding="utf-8") as outfile:with tqdm(total=total_lines, desc="合并进度", unit="line") as pbar:for filename in file_list:file_path = os.path.join(dir_path, filename)try:with open(file_path, "r", encoding="utf-8") as infile:file_size = os.path.getsize(file_path)chunk_size = max(1024 * 1024, file_size // 100)  # 动态调整读取块大小while True:lines = infile.readlines(chunk_size)if not lines:breakfor line_num, line in enumerate(lines, 1):line = line.strip()if not line:continuetry:data = json.loads(line)content = data.get("content", "").replace("\n", " ")  # 清除内容中的换行符outfile.write(content + "\n\n")  # 用双换行分隔记录processed_lines += 1except json.JSONDecodeError:print(f"\nJSON解析失败: {filename} 第{processed_lines + 1}行")except Exception as e:print(f"\n处理异常: {filename} 第{processed_lines + 1}行 - {str(e)}")# 进度更新pbar.update(1)if processed_lines % 1000 == 0:elapsed = time.time() - start_timespeed = processed_lines / (elapsed + 1e-5)remaining = (total_lines - processed_lines) / (speed + 1e-5)pbar.set_postfix({'速度': f"{speed:.1f} lines/s",'剩余时间': f"{remaining // 3600:.0f}h {remaining % 3600 // 60:.0f}m"})processed_files += 1except Exception as e:print(f"\n无法读取文件 {filename}: {str(e)}")# 生成统计报告end_time = time.time()print(f"\n合并完成!共处理 {processed_files}/{total_files} 个文件")print(f"总记录数: {processed_lines:,} 条")print(f"耗时: {end_time - start_time:.2f} 秒")print(f"输出文件路径: {output_file}")if __name__ == "__main__":process_files()

http://www.dtcms.com/wzjs/490900.html

相关文章:

  • 做网站用什么版本系统建网站找哪个平台好呢
  • 互联网运营网站中国万网域名注册免费
  • 网站建设中网站制作包括哪些内容百度指数pc版
  • 域名空间都有了怎么做网站东莞seo排名扣费
  • 网站外链发布平台排名检测
  • 做衣服的网站网站排名监控工具
  • 网站设计配色方案百度2023免费
  • 杭州企业网站制作建站abc网站
  • wordpress评论采集插件企业关键词优化公司
  • 个人网站免费域名获取seo描述是什么
  • 没有网站怎么做网推成人技能培训
  • 怎么做网站赚钱的动漫网站百度产品推广怎么收费
  • 手机网站的作用进入百度一下官网
  • 重庆seo整站优化方案范文百度推广关键词规划师
  • 淄博 网站建设营销模式都有哪些
  • ui设计岗前培训3个月骗局seo首页网站
  • 海外网站怎么浏览网络软文营销
  • 网站错误页面模板今日国内新闻最新消息
  • 厦门做网站培训网络营销策划书8000字
  • 宣城市建设监督管理局网站公司网站建设哪家公司好
  • 外包网接单seo关键词工具
  • 百度做网站多少钱能做无锡百姓网推广
  • 怎么做网站的浏览栏说到很多seo人员都转行了
  • 自适应网站开发书籍爱站网关键词长尾挖掘工具
  • 淘宝的好券网站怎么做郑州seo技术服务顾问
  • 网站线上体系怎么宣传自己的店铺
  • 网站内容页相关性怎么做网络营销策划与创意
  • 要做网站照片怎么处理青岛网站建设与设计制作
  • 网站模板免费下载php网站关键词怎么快速上排名
  • 天津做网站的公司怎么样平台推广费用一般是多少