|
|
@ -73,59 +73,45 @@ class AnalyzeByJSoup { |
|
|
|
return textS |
|
|
|
return textS |
|
|
|
} |
|
|
|
} |
|
|
|
//拆分规则 |
|
|
|
//拆分规则 |
|
|
|
val sourceRule = SourceRule(ruleStr) |
|
|
|
val elementsType: String |
|
|
|
if (isEmpty(sourceRule.elementsRule)) { |
|
|
|
val ruleStrS: Array<String> |
|
|
|
textS.add(element!!.data()) |
|
|
|
when { |
|
|
|
} else { |
|
|
|
ruleStr.contains("&&") -> { |
|
|
|
val elementsType: String |
|
|
|
elementsType = "&" |
|
|
|
val ruleStrS: Array<String> |
|
|
|
ruleStrS = ruleStr.splitNotBlank("&&") |
|
|
|
when { |
|
|
|
|
|
|
|
sourceRule.elementsRule.contains("&&") -> { |
|
|
|
|
|
|
|
elementsType = "&" |
|
|
|
|
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("&&") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sourceRule.elementsRule.contains("%%") -> { |
|
|
|
|
|
|
|
elementsType = "%" |
|
|
|
|
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("%%") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
elementsType = "|" |
|
|
|
|
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("||") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
val results = ArrayList<List<String>>() |
|
|
|
ruleStr.contains("%%") -> { |
|
|
|
for (ruleStrX in ruleStrS) { |
|
|
|
elementsType = "%" |
|
|
|
val temp: List<String>? |
|
|
|
ruleStrS = ruleStr.splitNotBlank("%%") |
|
|
|
temp = if (sourceRule.isCss) { |
|
|
|
} |
|
|
|
val lastIndex = ruleStrX.lastIndexOf('@') |
|
|
|
else -> { |
|
|
|
getResultLast( |
|
|
|
elementsType = "|" |
|
|
|
element!!.select(ruleStrX.substring(0, lastIndex)), |
|
|
|
ruleStrS = ruleStr.splitNotBlank("||") |
|
|
|
ruleStrX.substring(lastIndex + 1) |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} else { |
|
|
|
val results = ArrayList<List<String>>() |
|
|
|
getResultList(ruleStrX) |
|
|
|
for (ruleStrX in ruleStrS) { |
|
|
|
} |
|
|
|
val temp: List<String>? = getResultList(ruleStrX) |
|
|
|
if (temp != null && temp.isNotEmpty()) { |
|
|
|
if (temp != null && temp.isNotEmpty()) { |
|
|
|
results.add(temp) |
|
|
|
results.add(temp) |
|
|
|
if (results.isNotEmpty() && elementsType == "|") { |
|
|
|
if (results.isNotEmpty() && elementsType == "|") { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (results.size > 0) { |
|
|
|
} |
|
|
|
if ("%" == elementsType) { |
|
|
|
if (results.size > 0) { |
|
|
|
for (i in 0 until results[0].size) { |
|
|
|
if ("%" == elementsType) { |
|
|
|
for (temp in results) { |
|
|
|
for (i in 0 until results[0].size) { |
|
|
|
if (i < temp.size) { |
|
|
|
|
|
|
|
textS.add(temp[i]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for (temp in results) { |
|
|
|
for (temp in results) { |
|
|
|
textS.addAll(temp) |
|
|
|
if (i < temp.size) { |
|
|
|
|
|
|
|
textS.add(temp[i]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for (temp in results) { |
|
|
|
|
|
|
|
textS.addAll(temp) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return textS |
|
|
|
return textS |
|
|
@ -139,39 +125,28 @@ class AnalyzeByJSoup { |
|
|
|
if (temp == null || isEmpty(rule)) { |
|
|
|
if (temp == null || isEmpty(rule)) { |
|
|
|
return elements |
|
|
|
return elements |
|
|
|
} |
|
|
|
} |
|
|
|
val sourceRule = SourceRule(rule) |
|
|
|
|
|
|
|
val elementsType: String |
|
|
|
val elementsType: String |
|
|
|
val ruleStrS: Array<String> |
|
|
|
val ruleStrS: Array<String> |
|
|
|
when { |
|
|
|
when { |
|
|
|
sourceRule.elementsRule.contains("&&") -> { |
|
|
|
rule.contains("&&") -> { |
|
|
|
elementsType = "&" |
|
|
|
elementsType = "&" |
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("&&") |
|
|
|
ruleStrS = rule.splitNotBlank("&&") |
|
|
|
} |
|
|
|
} |
|
|
|
sourceRule.elementsRule.contains("%%") -> { |
|
|
|
rule.contains("%%") -> { |
|
|
|
elementsType = "%" |
|
|
|
elementsType = "%" |
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("%%") |
|
|
|
ruleStrS = rule.splitNotBlank("%%") |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
elementsType = "|" |
|
|
|
elementsType = "|" |
|
|
|
ruleStrS = sourceRule.elementsRule.splitNotBlank("||") |
|
|
|
ruleStrS = rule.splitNotBlank("||") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
val elementsList = ArrayList<Elements>() |
|
|
|
val elementsList = ArrayList<Elements>() |
|
|
|
if (sourceRule.isCss) { |
|
|
|
for (ruleStr in ruleStrS) { |
|
|
|
for (ruleStr in ruleStrS) { |
|
|
|
val tempS = getElementsSingle(temp, ruleStr) |
|
|
|
val tempS = temp.select(ruleStr) |
|
|
|
elementsList.add(tempS) |
|
|
|
elementsList.add(tempS) |
|
|
|
if (tempS.size > 0 && elementsType == "|") { |
|
|
|
if (tempS.size > 0 && elementsType == "|") { |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for (ruleStr in ruleStrS) { |
|
|
|
|
|
|
|
val tempS = getElementsSingle(temp, ruleStr) |
|
|
|
|
|
|
|
elementsList.add(tempS) |
|
|
|
|
|
|
|
if (tempS.size > 0 && elementsType == "|") { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (elementsList.size > 0) { |
|
|
|
if (elementsList.size > 0) { |
|
|
@ -302,7 +277,7 @@ class AnalyzeByJSoup { |
|
|
|
elementsByText = filterElements(elementsByText, filterRules) |
|
|
|
elementsByText = filterElements(elementsByText, filterRules) |
|
|
|
elements.addAll(elementsByText) |
|
|
|
elements.addAll(elementsByText) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> elements.addAll(temp.select(rulePcx[0])) |
|
|
|
else -> elements.addAll(temp.select(rule)) |
|
|
|
} |
|
|
|
} |
|
|
|
if (rulePcx.size > 1) { |
|
|
|
if (rulePcx.size > 1) { |
|
|
|
val rulePcs = rulePcx[1].splitNotBlank(":") |
|
|
|
val rulePcs = rulePcx[1].splitNotBlank(":") |
|
|
@ -386,18 +361,4 @@ class AnalyzeByJSoup { |
|
|
|
return textS |
|
|
|
return textS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal inner class SourceRule(ruleStr: String) { |
|
|
|
|
|
|
|
var isCss = false |
|
|
|
|
|
|
|
var elementsRule: String |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
if (ruleStr.startsWith("@CSS:", true)) { |
|
|
|
|
|
|
|
isCss = true |
|
|
|
|
|
|
|
elementsRule = ruleStr.substring(5).trim { it <= ' ' } |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
elementsRule = ruleStr |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|