当前位置:网站首页>爬虫文本数据清洗
爬虫文本数据清洗
2022-07-31 01:25:00 【浪里摸鱼】
def filter_chars(text):
"""过滤无用字符 :param text: 文本 """
# 找出文本中所有非中,英和数字的字符
add_chars = set(re.findall(r'[^\u4e00-\u9fa5a-zA-Z0-9]', text))
extra_chars = set(r"""!!¥$%*()()-——【】::“”";;'‘’,。?,.?、""")
add_chars = add_chars.difference(extra_chars)
# tab 是/t
# 替换特殊字符组合
text = re.sub('{IMG:.?.?.?}', '', text)
text = re.sub(r'<!--IMG_\d+-->', '', text)
text = re.sub('(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', '', text) # 过滤网址
text = re.sub('<a[^>]*>', '', text).replace("</a>", "") # 过滤a标签
text = text.replace("</P>", "")
text = text.replace("nbsp;", "")
text = re.sub('<P[^>]*>', '', text, flags=re.IGNORECASE).replace("</p>", "") # 过滤P标签
text = re.sub('<strong[^>]*>', ',', text).replace("</strong>", "") # 过滤strong标签
text = re.sub('<br>', ',', text) # 过滤br标签
text = re.sub('www.[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', '', text).replace("()", "") # 过滤www开头的网址
text = re.sub(r'\s', '', text) # 过滤不可见字符
text = re.sub('Ⅴ', 'V', text)
# 清洗
for c in add_chars:
text = text.replace(c, '')
return text
边栏推荐
- 分布式.分布式锁
- kotlin中函数作为参数和函数作为返回值实例练习
- TiDB之rawkv升级之路v5.0.4--&gt;v6.1.0
- link与@import的区别
- Mysql:Invalid default value for TIMESTAMP
- tensorflow与GPU版本对应安装问题
- The difference between 4G communication module CAT1 and CAT4
- Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar
- 想要写出好的测试用例,先要学会测试设计
- "Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis
猜你喜欢

typescript15- (specify both parameter and return value types)

tensorflow与GPU版本对应安装问题

Bert usage and word prediction based on Keras_bert model

设置浏览器滚动条样式

typescript15-(同时指定参数和返回值类型)

九州云获评云计算标准化优秀成员单位

Unity2D horizontal version game tutorial 4 - item collection and physical materials

typescript11 - data types

基于Keras_bert模型的Bert使用与字词预测

tkinter模块高级操作(二)—— 界面切换效果、立体阴影字效果及gif动图的实现
随机推荐
一万了解 Gateway 知识点
ShardingSphere's vertical sub-database sub-table actual combat (5)
297. 二叉树的序列化与反序列化
Why use high-defense CDN when financial, government and enterprises are attacked?
太阳能板最大面积 od js
ECCV 2022 华科&ETH提出首个用于伪装实例分割的一阶段Transformer的框架OSFormer!代码已开源!
Word 表格跨页,仍然显示标题
4G通信模块CAT1和CAT4的区别
24. Please talk about the advantages and disadvantages of the singleton pattern, precautions, usage scenarios
typescript10-常用基础类型
Set the browser scrollbar style
MySQL高级-六索引优化
MySQL (6)
小黑leetcode之旅:104. 二叉树的最大深度
【genius_platform软件平台开发】第七十四讲:window环境下的静态库和动态库的一些使用方法(VC环境)
数字图像隐写术之JPEG 隐写分析
查看zabbix-release-5.0-1.el8.noarch.rpm包内容
ShardingSphere read-write separation (8)
系统设计.短链系统设计
Basic Parameters of RF Devices 1