当前位置:网站首页>爬虫文本数据清洗
爬虫文本数据清洗
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
边栏推荐
- Google官方控件ShapeableImageView使用
- Yolov7实战,实现网页端的实时目标检测
- The difference between 4G communication module CAT1 and CAT4
- 认识DTU什么是4GDTU设备
- 网站频繁出现mysql等数据库连接失败等信息解决办法
- VS warning LNK4099:未找到 PDB 的解决方案
- MySql data recovery method personal summary
- Why use high-defense CDN when financial, government and enterprises are attacked?
- Multiplication, DFS order
- 使用docker安装mysql
猜你喜欢
JS逆向之浏览器补环境(一)
typescript16-void
Installation problem corresponding to tensorflow and GPU version
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
typescript9-常用基础类型
Xiaohei's leetcode journey: 104. The maximum depth of a binary tree
调度中心xxl-Job
typescript13 - type aliases
【952. Calculate the maximum component size according to the common factor】
Ticmp - 更快的让应用从 MySQL 迁移到 TiDB
随机推荐
手把手教你配置Jenkins自动化邮件通知
typescript15- (specify both parameter and return value types)
C language _ structure pointer array function voting system
MySQL (6)
typescript10-commonly used basic types
35. Reverse linked list
这个项目太有极客范儿了
typescript14-(单独指定参数和返回值的类型)
金融政企被攻击为什么要用高防CDN?
typescript16-void
PDF 拆分/合并
软件测试要达到一个什么水平才能找到一份9K的工作?
使用docker安装mysql
华为od 转骰子 js
查看zabbix-release-5.0-1.el8.noarch.rpm包内容
聚簇索引和非聚簇索引到底有什么区别
斩获BAT、TMD技术专家Offer,我都经历了什么?
ROS2系列知识(3):环境配置
孩子的编程启蒙好伙伴,自己动手打造小世界,长毛象教育AI百变编程积木套件上手
Bert usage and word prediction based on Keras_bert model