所以我做了网站刮刀,我想在这个请求函数中使用其他函数中的字符串,但我不能回复它。我不确定管道是如何工作的。
request(realAnswer, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var tree = $('.qa-answer-field');
var final = tree.children().eq(1).text();//i want to use this final as a sting in other fucntion
}
}).pipe(final);
这个解决方案工作正常,但我只能在控制台中写出我的结果......
request(realAnswer, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var tree = $('.qa-answer-field');
var final = tree.children().eq(1).text();
if(final)
console.log("Response: \n"+final);
else
console.error("Response doesnt exist!");
}
});
那么有人可以帮我解决我的问题吗?
答案 0 :(得分:0)
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(true).build())
.build();
Fabric.with(this, crashlyticsKit);
或者你可以使用像
这样的对象字符串 var usemepls = 'fake'
request(realAnswer, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var tree = $('.qa-answer-field');
var final = tree.children().eq(1).text();
if(final)
console.log("Response: \n"+final);
usemepls = final.toString() // <-- if you dont want a string just replace the .toString()
else
console.error("Response doesnt exist!");
}
})
console.log('usemepls: ' + usemepls)
或者您可以使用功能
var usemepls = {}
request(realAnswer, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var tree = $('.qa-answer-field');
var final = tree.children().eq(1).text();
if(final)
console.log("Response: \n"+final);
usemepls.test1 = final.toString() // <-- if you dont want a string just replace the .toString()
else
console.error("Response doesnt exist!");
}
})
console.log('usemepls.test1: ' + usemepls.test1)
你应该更多地了解javascript / node.js的基础知识。它会让你更轻松。