Javascript 节点js上的ChereIO出错
我试图在节点Js上用cheerio和request解析代码,我得到了错误Javascript 节点js上的ChereIO出错,javascript,node.js,request,cheerio,Javascript,Node.js,Request,Cheerio,我试图在节点Js上用cheerio和request解析代码,我得到了错误undefined我已经检查过了,这不是请求错误,是cheerio 这里是我的部分解析代码 const options = Object.assign({ url: buildUrl(opts), followAllRedirects: true }, opts.requestOptions); request(options, opts.throttle)
undefined
我已经检查过了,这不是请求错误,是cheerio
这里是我的部分解析代码
const options = Object.assign({
url: buildUrl(opts),
followAllRedirects: true
}, opts.requestOptions);
request(options, opts.throttle)
.then(cheerio.load)
.then(parseFields)
.then(function (app) {
resolve(app);
})
.catch(reject);
});
}
function parseFields ($) {
const h2 = $('faq_cat').attr('id')
const fields = {
h2
};
我要分析的是什么
<div class="faq_cat" id="faq_box_faq2">
使用console.log(h2)
代码屏幕
使用console.log($.html())
银幕工作!
您的选择器缺少一个
现在您正在寻找一个名为faq\u cat
的标签,该标签不存在。您想选择类名为faq\u cat
使用
const h2=$('.faq_cat').attr('id')
您从哪里得到未定义的?完整的错误消息是什么?在node js命令行(Windows上的命令提示符)中,这是一个完整的错误消息@ББМСааааааааааааа?如果是这样的话,你也能展示一下这个部分吗?是的,我只是发送了console.log和expressserver应用程序的代码,为什么你不试着放一个console.log(h2)
紧接着const h2=$('faq\u cat').attr('id')
并查看它是否打印faq\u box\u faq2
我还可以发送给您一个我试图解析的站点。您确定要将页面HTML传递到cheerio.load
函数中吗?
const express = require('express')
const app = express()
var gplay = require('google-play-scraper');
gplay.download({downloadId: 'air.com.helloair.HELLOFROG',
nameid: 'digital-world-digimons'})
.then(console.log, console.log);
app.listen(3000, () => console.log('Example app listening on port 3000!'))