|
@@ -258,6 +258,7 @@ class AnalyzeRule(
|
|
|
} else {
|
|
} else {
|
|
|
getAnalyzeByJSoup(it).getString(sourceRule.rule)
|
|
getAnalyzeByJSoup(it).getString(sourceRule.rule)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else -> sourceRule.rule
|
|
else -> sourceRule.rule
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -307,6 +308,7 @@ class AnalyzeRule(
|
|
|
result.toString(),
|
|
result.toString(),
|
|
|
sourceRule.rule.splitNotBlank("&&")
|
|
sourceRule.rule.splitNotBlank("&&")
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
Mode.Js -> evalJS(sourceRule.rule, it)
|
|
Mode.Js -> evalJS(sourceRule.rule, it)
|
|
|
Mode.Json -> getAnalyzeByJSonPath(it).getObject(sourceRule.rule)
|
|
Mode.Json -> getAnalyzeByJSonPath(it).getObject(sourceRule.rule)
|
|
|
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
|
|
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
|
|
@@ -339,6 +341,7 @@ class AnalyzeRule(
|
|
|
result.toString(),
|
|
result.toString(),
|
|
|
sourceRule.rule.splitNotBlank("&&")
|
|
sourceRule.rule.splitNotBlank("&&")
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
Mode.Js -> evalJS(sourceRule.rule, result)
|
|
Mode.Js -> evalJS(sourceRule.rule, result)
|
|
|
Mode.Json -> getAnalyzeByJSonPath(it).getList(sourceRule.rule)
|
|
Mode.Json -> getAnalyzeByJSonPath(it).getList(sourceRule.rule)
|
|
|
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
|
|
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
|
|
@@ -389,7 +392,7 @@ class AnalyzeRule(
|
|
|
if (rule.replaceRegex.isEmpty()) return result
|
|
if (rule.replaceRegex.isEmpty()) return result
|
|
|
var vResult = result
|
|
var vResult = result
|
|
|
vResult = if (rule.replaceFirst) {
|
|
vResult = if (rule.replaceFirst) {
|
|
|
- /* ##match##replace### 获取第一个匹配到的结果并进行替换 */
|
|
|
|
|
|
|
+ /* ##match##replace### 获取第一个匹配到的结果并进行替换 */
|
|
|
kotlin.runCatching {
|
|
kotlin.runCatching {
|
|
|
val pattern = Pattern.compile(rule.replaceRegex)
|
|
val pattern = Pattern.compile(rule.replaceRegex)
|
|
|
val matcher = pattern.matcher(vResult)
|
|
val matcher = pattern.matcher(vResult)
|
|
@@ -402,7 +405,7 @@ class AnalyzeRule(
|
|
|
rule.replacement
|
|
rule.replacement
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- /* ##match##replace 替换*/
|
|
|
|
|
|
|
+ /* ##match##replace 替换*/
|
|
|
kotlin.runCatching {
|
|
kotlin.runCatching {
|
|
|
vResult.replace(rule.replaceRegex.toRegex(), rule.replacement)
|
|
vResult.replace(rule.replaceRegex.toRegex(), rule.replacement)
|
|
|
}.getOrElse {
|
|
}.getOrElse {
|
|
@@ -476,26 +479,32 @@ class AnalyzeRule(
|
|
|
mode = Mode.Default
|
|
mode = Mode.Default
|
|
|
ruleStr
|
|
ruleStr
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
ruleStr.startsWith("@@") -> {
|
|
ruleStr.startsWith("@@") -> {
|
|
|
mode = Mode.Default
|
|
mode = Mode.Default
|
|
|
ruleStr.substring(2)
|
|
ruleStr.substring(2)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
ruleStr.startsWith("@XPath:", true) -> {
|
|
ruleStr.startsWith("@XPath:", true) -> {
|
|
|
mode = Mode.XPath
|
|
mode = Mode.XPath
|
|
|
ruleStr.substring(7)
|
|
ruleStr.substring(7)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
ruleStr.startsWith("@Json:", true) -> {
|
|
ruleStr.startsWith("@Json:", true) -> {
|
|
|
mode = Mode.Json
|
|
mode = Mode.Json
|
|
|
ruleStr.substring(6)
|
|
ruleStr.substring(6)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
isJSON || ruleStr.startsWith("$.") || ruleStr.startsWith("$[") -> {
|
|
isJSON || ruleStr.startsWith("$.") || ruleStr.startsWith("$[") -> {
|
|
|
mode = Mode.Json
|
|
mode = Mode.Json
|
|
|
ruleStr
|
|
ruleStr
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
ruleStr.startsWith("/") -> {//XPath特征很明显,无需配置单独的识别标头
|
|
ruleStr.startsWith("/") -> {//XPath特征很明显,无需配置单独的识别标头
|
|
|
mode = Mode.XPath
|
|
mode = Mode.XPath
|
|
|
ruleStr
|
|
ruleStr
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else -> ruleStr
|
|
else -> ruleStr
|
|
|
}
|
|
}
|
|
|
//分离put
|
|
//分离put
|
|
@@ -523,10 +532,12 @@ class AnalyzeRule(
|
|
|
ruleType.add(getRuleType)
|
|
ruleType.add(getRuleType)
|
|
|
ruleParam.add(tmp.substring(6, tmp.lastIndex))
|
|
ruleParam.add(tmp.substring(6, tmp.lastIndex))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
tmp.startsWith("{{") -> {
|
|
tmp.startsWith("{{") -> {
|
|
|
ruleType.add(jsRuleType)
|
|
ruleType.add(jsRuleType)
|
|
|
ruleParam.add(tmp.substring(2, tmp.length - 2))
|
|
ruleParam.add(tmp.substring(2, tmp.length - 2))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else -> {
|
|
else -> {
|
|
|
splitRegex(tmp)
|
|
splitRegex(tmp)
|
|
|
}
|
|
}
|
|
@@ -592,6 +603,7 @@ class AnalyzeRule(
|
|
|
}
|
|
}
|
|
|
} ?: infoVal.insert(0, ruleParam[index])
|
|
} ?: infoVal.insert(0, ruleParam[index])
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
regType == jsRuleType -> {
|
|
regType == jsRuleType -> {
|
|
|
if (isRule(ruleParam[index])) {
|
|
if (isRule(ruleParam[index])) {
|
|
|
getString(arrayListOf(SourceRule(ruleParam[index]))).let {
|
|
getString(arrayListOf(SourceRule(ruleParam[index]))).let {
|
|
@@ -606,13 +618,16 @@ class AnalyzeRule(
|
|
|
0,
|
|
0,
|
|
|
String.format("%.0f", jsEval)
|
|
String.format("%.0f", jsEval)
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
else -> infoVal.insert(0, jsEval.toString())
|
|
else -> infoVal.insert(0, jsEval.toString())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
regType == getRuleType -> {
|
|
regType == getRuleType -> {
|
|
|
infoVal.insert(0, get(ruleParam[index]))
|
|
infoVal.insert(0, get(ruleParam[index]))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else -> infoVal.insert(0, ruleParam[index])
|
|
else -> infoVal.insert(0, ruleParam[index])
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -667,6 +682,7 @@ class AnalyzeRule(
|
|
|
"bookName" -> book?.let {
|
|
"bookName" -> book?.let {
|
|
|
return it.name
|
|
return it.name
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
"title" -> chapter?.let {
|
|
"title" -> chapter?.let {
|
|
|
return it.title
|
|
return it.title
|
|
|
}
|
|
}
|
|
@@ -694,15 +710,19 @@ class AnalyzeRule(
|
|
|
bindings["title"] = chapter?.title
|
|
bindings["title"] = chapter?.title
|
|
|
bindings["src"] = content
|
|
bindings["src"] = content
|
|
|
bindings["nextChapterUrl"] = nextChapterUrl
|
|
bindings["nextChapterUrl"] = nextChapterUrl
|
|
|
-// return Rhino.use {
|
|
|
|
|
-// val scope = initStandardObjects()
|
|
|
|
|
|
|
+// return Rhino.use { scope ->
|
|
|
// scope.putBindings(bindings)
|
|
// scope.putBindings(bindings)
|
|
|
// source?.getShareScope()?.let {
|
|
// source?.getShareScope()?.let {
|
|
|
// scope.prototype = it
|
|
// scope.prototype = it
|
|
|
// }
|
|
// }
|
|
|
-// evaluate(scope, jsStr)
|
|
|
|
|
|
|
+// eval(scope, jsStr)
|
|
|
// }
|
|
// }
|
|
|
- return RhinoScriptEngine.eval(jsStr, SimpleBindings(bindings))
|
|
|
|
|
|
|
+ val context = RhinoScriptEngine.getScriptContext(SimpleBindings(bindings))
|
|
|
|
|
+ val scope = RhinoScriptEngine.getRuntimeScope(context)
|
|
|
|
|
+ source?.getShareScope()?.let {
|
|
|
|
|
+ scope.prototype = it
|
|
|
|
|
+ }
|
|
|
|
|
+ return RhinoScriptEngine.eval(jsStr, scope)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun getSource(): BaseSource? {
|
|
override fun getSource(): BaseSource? {
|