Explorar el Código

feat:数据详情清洗逻辑修改

yangyi hace 1 mes
padre
commit
3da2693954

+ 21 - 17
src/main/java/space/anyi/cleaner/DetailCleaner.java

@@ -49,23 +49,27 @@ public class DetailCleaner {
      */
     public static String clean(String html) {
         Document doc = Jsoup.parse(html);
-        doc.select("meta, script").remove();
-        doc.select("#hidden-box").remove();
-        doc.select("div.hidden-box").remove();
-        for (Element container : doc.select("div.container")) {
-            Elements children = new Elements();
-            container.children().forEach(children::add);
-            for (Element child : children) {
-                boolean keep = child.is("div")
-                        && (child.hasClass("article-title")
-                        || child.hasClass("not-exist-media-leader")
-                        || child.hasClass("article-content"));
-                if (!keep) {
-                    child.remove();
-                }
-            }
-        }
-        return doc.html();
+
+        html = """
+                <!DOCTYPE html>
+                <html lang="en" style="font-size: 18px;">
+                <head></head>
+                <body>
+                </body>
+                </html>
+                """;
+        Document result = Jsoup.parse(html);
+
+        Elements style = doc.select("link[rel='stylesheet']");
+        Element head = result.head();
+        head.insertChildren(0, style);
+
+        Element container = doc.select("div.container").first();
+        Elements keep = container.children().select("div.article-title, div.not-exist-media-leader, div.article-content");
+        keep.select("video").remove();
+        result.body().appendChildren(keep);
+
+        return result.html();
     }
 
     /**

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 199 - 0
src/test/java/space/anyi/MyListTest.java


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio