0
我正在製作一個bot的東西,它被設計爲移動到文件的下一個'頁面'並搜索一個字符串,並重復這個動作直到找到該字符串。一切工作,在搜索字符串,但它只能導航到下一頁一次(所以它只能去online.php?page = 2。我相信這是因爲iframe.contentWindow.load只觸發一次,開代碼的第一次運行。因此,當它移動到一個新的頁面,它不是持續的。每次iframe重新導航時執行操作。 (javascript)
任何想法?
document.body.innerHTML = '' //Out with the old
var iframe = document.createElement('iframe');
var increm = 1
iframe.src = 'online.php?page=' + parseInt(increm)
iframe.style.height= '3000px'
iframe.style.width = '100%'
document.body.appendChild(iframe); //In with the new
$(iframe.contentWindow).load(function() { //Once EVERYTHING has loaded
runcode()
});
function runcode(){
whole = iframe.contentWindow.document.body.innerText
var sub = "StringToSearchFor";
if(whole.indexOf(sub) > -1){ //If the string is found on the page
console.log('The string has been found on this page')
}else{ //Otherwise
increm = increm+1
iframe.src = 'online.php?page=' + parseInt(increm); //Move to the next page
$(iframe.contentWindow).load(function() { //rinse
runcode() //repeat
});
}
}
我有一個處理程序(第一個)沒成功所以我添加了第二個,看看它是否會解決,兩種情況下的結果都是相同的。我原本以爲第一個負載處理程序會在每次iframe重新導航時重新觸發。有沒有可能通過iframe重新導航的具體方式,而不僅僅是改變src? – TheDmOfJoes
嘗試用別的東西替換innerText;) – yezzz
innerText是我如何搜索文檔的主體以查看特定字符串是否匹配。我可以使用innerHTML,但我認爲這不會有太大的區別... – TheDmOfJoes