From 39cced7cb02dcbe8c573aa632d47aa6664732267 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 13 Aug 2021 08:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeByJSoup.kt | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 7bc7186e4..d9e69c874 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -7,7 +7,6 @@ import org.jsoup.select.Collector import org.jsoup.select.Elements import org.jsoup.select.Evaluator import org.seimicrawler.xpath.JXNode -import java.util.* /** * Created by GKF on 2018/1/25. @@ -71,7 +70,7 @@ class AnalyzeByJSoup(doc: Any) { val results = ArrayList>() for (ruleStrX in ruleStrS) { - val temp: List? = + val temp: ArrayList? = if (sourceRule.isCss) { val lastIndex = ruleStrX.lastIndexOf('@') getResultLast( @@ -83,11 +82,8 @@ class AnalyzeByJSoup(doc: Any) { } if (!temp.isNullOrEmpty()) { - - results.add(temp) //!temp.isNullOrEmpty()时,results.isNotEmpty()为true - + results.add(temp) if (ruleAnalyzes.elementsType == "||") break - } } if (results.size > 0) { @@ -181,7 +177,7 @@ class AnalyzeByJSoup(doc: Any) { /** * 获取内容列表 */ - private fun getResultList(ruleStr: String): List? { + private fun getResultList(ruleStr: String): ArrayList? { if (ruleStr.isEmpty()) return null @@ -210,32 +206,42 @@ class AnalyzeByJSoup(doc: Any) { /** * 根据最后一个规则获取内容 */ - private fun getResultLast(elements: Elements, lastRule: String): List { + private fun getResultLast(elements: Elements, lastRule: String): ArrayList { val textS = ArrayList() try { when (lastRule) { "text" -> for (element in elements) { - textS.add(element.text()) + val text = element.text() + if (text.isNotEmpty()) { + textS.add(text) + } } "textNodes" -> for (element in elements) { val tn = arrayListOf() val contentEs = element.textNodes() for (item in contentEs) { - val temp = item.text().trim { it <= ' ' } - if (temp.isNotEmpty()) { - tn.add(temp) + val text = item.text().trim { it <= ' ' } + if (text.isNotEmpty()) { + tn.add(text) } } - textS.add(tn.joinToString("\n")) + if (tn.isNotEmpty()) { + textS.add(tn.joinToString("\n")) + } } "ownText" -> for (element in elements) { - textS.add(element.ownText()) + val text = element.ownText() + if (text.isNotEmpty()) { + textS.add(text) + } } "html" -> { elements.select("script").remove() elements.select("style").remove() val html = elements.outerHtml() - textS.add(html) + if (html.isNotEmpty()) { + textS.add(html) + } } "all" -> textS.add(elements.outerHtml()) else -> for (element in elements) {