背景:
基于jsoup(v 1.6.3)解析出来的网页内容进行过滤不需要的内容比如<script>
实现:
一种方式是基于tag的白名单,这种方式明显没有黑名单合适,不过jsoup木有提供黑名单功能
直接基于正则,常用的如下:
如:过滤<script>
String reg = "<\\s*?script[^>]*?>[\\s\\S]*?<\\s*?/\\s*?script\\s*?>";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(content.html());
articleVo.setContent(matcher.replaceAll(""));
本文介绍了如何使用JSoup库基于正则表达式过滤网页内容中的<script>标签,通过设置白名单避免误操作,确保网页内容的纯净。
4256

被折叠的 条评论
为什么被折叠?



