0
我正在使用nightmare.js在中國電子商務網站taobao(www.taobao.com/)上進行網頁腳本編寫。目標是獲取產品信息。該代碼與yahoo example code非常相似,但結果始終爲空。我試圖把console.log調試,並意識到可能存在於querySelector中的錯誤。 下面是如果有人有時間去看看的代碼。真的很感激它。無法使用node.js上的惡夢API返回document.querySelector
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('https://www.taobao.com')
.type('form[action*="/search"] [name=q]', 'hellow kitty')
.click('form[action*="/search"] [type=submit]')
.wait(2000)
.evaluate(function() {
return document.querySelector('.row.row-2.title a')
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
只是試圖去那個網站,做一個搜索'凱蒂貓',..沒有什麼與'.row'甚至'.row-2'類。但是,如果我做'document.querySelectorAll('。item')'這會給你所有的產品在頁面上,如果這是你的事後。 – Keith
使用截圖()查看執行評估時在目標頁面上呈現的內容。如果你正在嘗試閱讀的元素是否存在,那麼這應該給你一個公平的想法。 –