我正在尝试抓取网站内容。
为了进行测试,我尝试将Stackoverflow加载到inAppBrowser中并获取其内容。这就是我尝试过的
var code = "alert(document.getElementsByClassName('question-hyperlink').length)";
var win = window.open('https://stackoverflow.com/questions/20937196/retrieving-source-code-of-site-in-inappbrowser/', '_blank', 'location=yes');
win.addEventListener('loadstop', function(event) {
//wait 1 second till page load
setTimeout(function(){
win.executeScript({
code: code,
}, function() {
console.log('script was injected successfully');
});
}, 1000);
});
它仅返回值1
但是该页面有超过35个元素,类为question-hyperlink
。如何从inApp正确访问内容