0
我正在寫一個噩夢腳本,在Web窗體中鍵入名稱並讀取打印在表格中的結果。我已經做了輸入打字,並得到這樣的表結果:Nightmarejs - 我如何讀取表格行內容?
{ jQuery110205953448106032428: 124 }
所以我不知道如何從這個元素讀取行。
我現在的腳本是:
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })
nightmare
.goto('https://rnped.segob.gob.mx/')
.click('small#leyendacomun')
.wait(2000)
.type('input#comun_c_nombre', 'María')
.type('input#comun_c_apaterno', 'Hernández')
.click('button#busca_comun')
.wait(2000)
.evaluate(function() {
return document.querySelector('table#t_comun')
// Here I select and return the <table>
})
.end()
.then(function (result) {
console.log(result)
// Here I get { jQuery110205953448106032428: 124 }
})
.catch(function (error) {
console.error('Error:', error);
});
如何,我可以從查詢選擇獲取錶行?
好的,非常感謝!我怎麼能遍歷結果表的所有頁面,我也必須在評估函數中做到這一點? – forkfork
您可以在您自己的瀏覽器中進行測試:編寫一個腳本,將您需要的所有數據提取到數組或對象中。然後在'evaluate()'函數中使用相同的代碼並返回結果。 – Sirko