Skip to content

Commit

Permalink
Feat: improve the request & xpath method
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Aug 26, 2023
1 parent 0078c7a commit a3e7fa6
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/utils/extension_runtime.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:xpath_selector_html_parser/xpath_selector_html_parser.dart';
import 'dart:io';
Expand Down Expand Up @@ -53,14 +54,18 @@ class ExtensionRuntime {
ExtensionUtils.addLog(
extension,
ExtensionLogLevel.info,
"GET: ${args[0]} , ${args[1]}",
"Request: ${args[0]} , ${args[1]}",
);
_cuurentRequestUrl = args[0];
return (await _dio.get<String>(args[0],
options: Options(
headers: args[1]['headers'] ?? {},
method: args[1]['method'] ?? 'get',
)))
return (await _dio.request<String>(
args[0],
data: args[1]['data'],
queryParameters: args[1]['queryParameters'] ?? {},
options: Options(
headers: args[1]['headers'] ?? {},
method: args[1]['method'] ?? 'get',
),
))
.data;
});

Expand Down Expand Up @@ -138,6 +143,12 @@ class ExtensionRuntime {
return jsonEncode(result.attrs);
case 'text':
return result.node?.text;
case 'allHTML':
return result.nodes
.map((e) => (e.node as Element).outerHtml)
.toList();
case 'outerHTML':
return (result.node?.node as Element).outerHtml;
default:
return result.node?.text;
}
Expand Down Expand Up @@ -248,6 +259,14 @@ class ExtensionRuntime {
get text() {
return this.excute("text");
}
get allHTML() {
return this.excute("allHTML");
}
get outerHTML() {
return this.excute("outerHTML");
}
}
// 重写 console.log
Expand Down

0 comments on commit a3e7fa6

Please sign in to comment.