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

公司网站日常维护外贸网站都有哪些

公司网站日常维护,外贸网站都有哪些,网站充值支付宝收款怎么做,做文案策划需要用到的网站说明:我希望用nodejs 写一个小工具,去除本地txt文件中的html字符,去除字符后生成新的文件,同样保存在桌面 文件的具体位置是C:\Users\Administrator\Desktop\file.txt step1:C:\Users\Administrator\WebstormProjects\untitled4\f…

说明:我希望用nodejs 写一个小工具,去除本地txt文件中的html字符,去除字符后生成新的文件,同样保存在桌面 文件的具体位置是C:\Users\Administrator\Desktop\file.txt
step1:C:\Users\Administrator\WebstormProjects\untitled4\file.js

const fs = require('fs');
const path = require('path');
// 定义文件路径
const desktopPath = 'C:\\Users\\Administrator\\Desktop';
const inputFile = path.join(desktopPath, 'file.txt');
const outputFile = path.join(desktopPath, 'clean_file.txt');
// 自定义HTML实体替换规则
const htmlEntities = {'&lt;': '<','&gt;': '>','&amp;': '&','&quot;': '"','&apos;': "'",'&#39;': "'",'&nbsp;': ' ',
};
// 主处理函数
function cleanHtml(filePath) {try {// 读取文件内容const content = fs.readFileSync(filePath, 'utf8');// 分步骤清理内容let cleaned = content// 移除HTML标签.replace(/<[^>]+>/g, '')// 替换HTML实体.replace(/&(?:[a-z]+|#\d+);/gi, (match) =>htmlEntities[match.toLowerCase()] || match)// 清理多余换行和空格.replace(/\n{3,}/g, '\n\n').replace(/ {2,}/g, ' ');// 写入新文件fs.writeFileSync(outputFile, cleaned, 'utf8');console.log(`文件清理完成,已保存至:${outputFile}`);console.log(`清理前字符数:${content.length}`);console.log(`清理后字符数:${cleaned.length}`);console.log(`移除字符数:${content.length - cleaned.length}`);} catch (error) {console.error('处理文件时发生错误:');console.error(error.message);process.exit(1);}
}
// 执行清理
if (require.main === module) {// 检查源文件是否存在if (!fs.existsSync(inputFile)) {console.error(`错误:源文件 ${inputFile} 不存在`);process.exit(1);}console.log('正在清理HTML字符...');cleanHtml(inputFile);
}

step2: 运行

PS C:\Users\Administrator\WebstormProjects\untitled4> node file.js
正在清理HTML字符...
文件清理完成,已保存至:C:\Users\Administrator\Desktop\clean_file.txt
清理前字符数:2235
清理后字符数:1697
移除字符数:538

下面是用python实现同样的功能 C:\Users\Administrator\PycharmProjects\PythonProject2.venv\Scripts\activate_this.py

from pathlib import Path
import re
import sys# 定义文件路径
desktop_path = Path(r'C:\Users\Administrator\Desktop')
input_file = desktop_path / 'file.txt'
output_file = desktop_path / 'cleans_file.txt'# 自定义HTML实体替换规则
html_entities = {'&lt;': '<','&gt;': '>','&amp;': '&','&quot;': '"','&apos;': "'",'&#39;': "'",'&nbsp;': ' ',
}def clean_html(file_path):try:# 读取文件内容with open(file_path, 'r', encoding='utf-8') as f:content = f.read()# 分步骤清理内容cleaned = content# 移除HTML标签cleaned = re.sub(r'<[^>]+>', '', cleaned)# 替换HTML实体def replace_entity(match):entity = match.text.lower()return html_entities.get(entity, match.text)cleaned = re.sub(r'&(?:[a-z]+|#\d+);',replace_entity,cleaned,flags=re.IGNORECASE)# 清理多余换行和空格cleaned = re.sub(r'\n{3,}', '\n\n', cleaned)cleaned = re.sub(r' {2,}', ' ', cleaned)# 写入新文件with open(output_file, 'w', encoding='utf-8') as f:f.write(cleaned)print(f'文件清理完成,已保存至:{output_file}')print(f'清理前字符数:{len(content)}')print(f'清理后字符数:{len(cleaned)}')print(f'移除字符数:{len(content) - len(cleaned)}')except Exception as e:print('处理文件时发生错误:')print(f'{e}')sys.exit(1)if __name__ == "__main__":# 检查源文件是否存在if not input_file.exists():print(f'错误:源文件 {input_file} 不存在')sys.exit(1)print('正在清理HTML字符...')clean_html(input_file)

end

http://www.ysxn.cn/news/1521.html

相关文章:

  • 网易官网建立个人网站廊坊seo网站管理
  • 百度搜索风云榜福州seo代理计费
  • 用友erp软件安卓优化大师清理
  • 国外网店平台有哪些关键词优化难度分析
  • 网站做长连接开发网站的流程
  • 外贸有哪些网站武汉刚刚突然宣布
  • wordpress网站转移网络营销课程ppt
  • 企业融资的意义重庆seo服务
  • 专业网站制作哪家强深圳网络营销推广服务
  • 网站建设与运营总结百度广告收费标准
  • 什么网站做视频最赚钱手机百度2020
  • 网站系统维护要多久网站推广什么意思
  • 唐山网站建设拓店铺如何运营和推广
  • html5 网站测试外链下载
  • 网络营销优化推广推广优化关键词
  • 要想让别人网站卖我的东西怎么做500个游戏推广群
  • 软件app下载大全信息流优化师需要具备哪些能力
  • 黄冈推广平台武汉seo搜索引擎
  • 做网站公司价格多少平面设计主要做什么
  • 国外黄冈网站推广短信营销
  • 江北网站建设价格网站快速优化排名排名
  • 深圳外贸公司排名seo做什么网站赚钱
  • 商城网站制作公司地址做个公司网站大概多少钱
  • 网站维护排名seminar什么意思中文
  • 社交网站开发语言搜索引擎排名
  • ecshop 做企业网站河北百度seo关键词
  • 网站建设没有签定合同搜索引擎优化课程
  • wordpress 视频模板下载地址重庆百度快照优化
  • 做ppt找素材的网站一个人怎么做独立站shopify
  • 做网站有必要要源码吗百度小说排行榜风云榜单