提问人:BazarOFF Elnur 提问时间:11/3/2023 更新时间:11/3/2023 访问量:10
解析 flutter 时如何等待网站上的微调器
How to wait for a spinner on a website when parsing flutter
问:
我能够使用选择器从站点接收数据,但是解析器每次更新都会输出多个结果,我对此进行了更正,使其仅接收 1 个结果,但是站点内部的微调器干扰了,我怎么能等待它关闭?
var result = await controller.evaluateJavascript(source: """
var spinner = document.querySelector('body > div.main_app > div:nth-child(6) > div.loader > div');
var spinnerStyle = window.getComputedStyle(spinner);
var spinnerVisible = spinnerStyle && spinnerStyle.visibility !== 'hidden' && spinnerStyle.display !== 'none';
spinnerVisible;
""");
debugPrint('loaded');
spinnerVisible = (result == 'true');
我尝试了很多东西,这是我尝试过的方法之一
child:Scaffold( backgroundColor: Colors.black54,
body: Column(children: <Widget>[
Expanded(
child: Stack(
children: [
const SizedBox(height: 60),
// Row( children: <Widget>[
// _buildProgressBar(),]),
InAppWebView(
key: webViewKey,
initialUrlRequest:
URLRequest(url: WebUri("https://sitename")),
initialSettings: settings,
pullToRefreshController: pullToRefreshController,
onWebViewCreated: (InAppWebViewController controller) {
webViewController = controller;
// contextMenu.menuItems.add(value)
},
onUpdateVisitedHistory: (webViewController, url, isReload) async {
},
// onJsBeforeUnload: ,
// onLoadStart: (webViewController, url){
//
// },
onLoadStop: (controller, url) async {
//pullToRefreshController?.endRefreshing();
// contextMenu.menuItems.add(ContextMenuItem(id: 2, title: "tttt", action: () async{
// controller.evaluateJavascript(source: """reply-tooltip.tooltip.flipped.reverse""");
// }));
},
onReceivedError: (controller, request, error) {
pullToRefreshController?.endRefreshing();
},
onProgressChanged: (controller, progress) async {
if (progress == 100) {
pullToRefreshController?.endRefreshing();
if ("https://fixuber.beeline.kz/installer/installersOrders/" != controller.getUrl().toString()){
Future<String?> waitForContentLoaded(InAppWebViewController controller) async {
bool spinnerVisible = true;
String? pageContent;
final js = "var progressBar = document.querySelector('body > div.main_app > div.blur'); if(progressBar) {if(progressBar.style.display === 'none') {true;} else {false;}} else {false;}";
final isProgressBarHidden = await controller.evaluateJavascript(source: js);
if (isProgressBarHidden == "true") {
String html = await webViewController?.evaluateJavascript(source: "document.documentElement.outerHTML");
RegExp exp = RegExp(r'<div.*?class="order_id">(.*?)</div>');
Iterable<RegExpMatch> matches = exp.allMatches(html);
List<String> spanList = [];
for (RegExpMatch match in matches){
spanList.add(match.group(1)!);
debugPrint(match.group(1)!);
debugPrint("its work top");
}
debugPrint(spanList.last);
}
var result = await controller.evaluateJavascript(source: """
var spinner = document.querySelector('body > div.main_app > div:nth-child(6) > div.loader > div');
var spinnerStyle = window.getComputedStyle(spinner);
var spinnerVisible = spinnerStyle && spinnerStyle.visibility !== 'hidden' && spinnerStyle.display !== 'none';
spinnerVisible;
""");
debugPrint('loaded');
spinnerVisible = (result == 'true');
pageContent = await controller.evaluateJavascript(source: "document.documentElement.outerHTML");
return pageContent;
}
String html = await webViewController?.evaluateJavascript(source: "document.documentElement.outerHTML");
// RegExp exp = RegExp(r'<div[^>]*class="order_id"[^>]*>(.*?)<\/div>');
// RegExp exp = RegExp(r'<div.*?class="order_id">(.*?)</div>');
RegExp checker = RegExp(r'<div.*?class="status--success">(.*?)</div>');
Iterable<RegExpMatch> checkerMatch = checker.allMatches(html);
List<String> checkerList = [];
Iterable<RegExpMatch> matches = checker.allMatches(html);
// Iterable<RegExpMatch> matches = exp.allMatches(html);
List<String> spanList = [];
if (checkerList.length == 0){
debugPrint("not match");
} else {
for (RegExpMatch match in matches){
if(match.group(1)!=null){
spanList.add(match.group(1)!);}
debugPrint(match.group(1)!);debugPrint("!its work bot");
}
debugPrint(spanList.last);debugPrint("its work bot");}}
//this.progress = progress / 100;
}
},
),
]),
),
])));
这基本上是我所有的代码,如果你帮忙,我会很高兴的
答: 暂无答案
评论