如何用JSoup和Diffator工具评估两段HTML内容的相似度?

更新于
2026-10-12 07:34:59
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计119个文字,预计阅读时间需要1分钟。

如何用JSoup和Diffator工具评估两段HTML内容的相似度?

python从HTML内容中提取纯文本内容

public static String getPlainText(String ) { if (StringUtils.isBlank()) { return ; } Element ebody=Jsoup.parseBodyFragment().body(); return ebody.select(code).text();}

gistfile1.txt

/** * 从一段HTML中萃取纯文本 * @param html * @return */ public static String getPlainText(String html){ if(StringUtils.isBlank(html)) return ""; Element ebody = Jsoup.parseBodyFragment(html).body(); ebody.select("code").remove(); ebody.select("pre").remove(); ebody.select("img").remove(); return ebody.text(); } /** * 计算两篇内容的相似度 * @param html1 * @param html2 * @return * @throws IOException */ public static double similarity(String html1, String html2) throws IOException { String text1 = getPlainText(html1); String text2 = getPlainText(html2); Content ct1 = new Content(tokenizer(text1)); Content ct2 = new Content(tokenizer(text2)); return ContentComparator.compareStatic(ct1, ct2); }

如何用JSoup和Diffator工具评估两段HTML内容的相似度?

本文共计119个文字,预计阅读时间需要1分钟。

如何用JSoup和Diffator工具评估两段HTML内容的相似度?

python从HTML内容中提取纯文本内容

public static String getPlainText(String ) { if (StringUtils.isBlank()) { return ; } Element ebody=Jsoup.parseBodyFragment().body(); return ebody.select(code).text();}

gistfile1.txt

/** * 从一段HTML中萃取纯文本 * @param html * @return */ public static String getPlainText(String html){ if(StringUtils.isBlank(html)) return ""; Element ebody = Jsoup.parseBodyFragment(html).body(); ebody.select("code").remove(); ebody.select("pre").remove(); ebody.select("img").remove(); return ebody.text(); } /** * 计算两篇内容的相似度 * @param html1 * @param html2 * @return * @throws IOException */ public static double similarity(String html1, String html2) throws IOException { String text1 = getPlainText(html1); String text2 = getPlainText(html2); Content ct1 = new Content(tokenizer(text1)); Content ct2 = new Content(tokenizer(text2)); return ContentComparator.compareStatic(ct1, ct2); }

如何用JSoup和Diffator工具评估两段HTML内容的相似度?