我必须在网站上进行某种“网络抓取”。我必须使用javascript依次导航并填写表格并提交,然后逐页加载。例如:
load login.html
fill user and password, submit
load homepage.html, fill some data, submit.
and so on.
问题在于每个Javascript必须在正确的页面上运行。
child: WebView(
onPageFinished: (p){
//execute javascript in the correct page.
},
initialUrl: 'http://www.google.com/',
onWebViewCreated: (c){
_controller = c;
},
javascriptMode: JavascriptMode.unrestricted,
)
因此,我使用_controller进行了一些网上剪贴簿:
_controller.loadUrl("http://www.example.com/login.htm");
// wait for on page finished on WebView.
_controller.evaluateJavascript('some javascript to fill login.htm forms and submit');
_controller.loadUrl("http://www.example.com/form1.htm");
// wait for on page finished on WebView.
_controller.evaluateJavascript('some javascript to fill form in form1.htm and submit');
_controller.loadUrl("http://www.example.com/result.htm");
// wait for on page finished on WebView.
var r = _controller.evaluateJavascript('use javascript to collect data from page');
问题是我无法以同步方式执行此操作。我认为Flutter / Dart可能具有一些同步机制来执行我想要的操作。但是我还不知道如何。