gpt4 book ai didi

javascript - 将参数传递给生成器 vo

转载 作者:行者123 更新时间:2023-12-03 07:54:34 25 4
gpt4 key购买 nike

我正在尝试使用 Nightmare js 抓取整个页面并将结果返回给调用函数。为了做到这一点,通过扩展 Nightmare 示例,我将参数传递给生成器函数。由于我不明白的原因, run() 函数永远不会被调用。

感谢您的帮助。

var Nightmare = require('nightmare');
var vo = require('vo');
const fs = require('fs');

url = "http://google.com";

vo( run(url) )(function(err, result) {
if (err) throw err;
console.log("end result length: ", result.length);

fs.writeFile("test.html", result, function(err) {
if(err) { return console.log(err); } })

});

function *run(url) {
console.trace()
var x = Date.now();
var nightmare = Nightmare();
var html = yield nightmare
.goto(url) // 'http://google.com')
.evaluate(function() {
return document.getElementsByTagName('html')[0].innerHTML;
});

console.log("done in " + (Date.now()-x) + "ms");
console.log("result:", html.length);

yield nightmare.end();
return html;
}

最佳答案

上面例子中的术语是错误的。这就是 vo 的工作原理:

vo( run )(url1, function(err, result) {
if (err) throw err;
console.log("end result length: ", result.length);

fs.writeFile("test.html", result, function(err) {
if(err) { return console.log(err); } })

});

关于javascript - 将参数传递给生成器 vo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com