NightmareでGoogleの検索結果をCSVに落とすコードを書こうと思っているのですが、題で書いているように、evaluate関数を抜けられません。
const Nightmare = require("nightmare"); const vo = require("vo"); vo(run)(function(err) { console.log("Finished!"); }); function* run() { const nightmare = Nightmare({ show: true }); const query = process.argv.splice(2).reduce((a, b) => a + b); yield nightmare .goto("https://google.com") .type( "#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input", query ) .click( '#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type="submit"]:nth-child(1)' ) .wait(1000) .evaluate(query => { var results = document.querySelectorAll("div.rc"); var csv = [[query, "", ""], ["title", "url", "discription"]]; for (var i = 0; i < results.length; i++) { csv.push([ results[i].querySelector("a").innerText.split("\n")[0], results[i].querySelector("a").href, results[i].querySelector("span.st").innerText ]); } // ここの時点でcsvという変数は正しく作られてる return csv; }) .then(csv => { // ここのthenが動かない console.log(csv); }) .end(); }
以上のコードを動かしたとき、コメントにある通り、evaluateのthenはうまく作られているのですが、thenのなかみが実行されません。
どうすればthenが実行されるかわかるでしょうか?
あなたの回答
tips
プレビュー