Node js 上的 Cheerio 出错
Error with Cheerio on Node js
我正在尝试使用 cheerio 解析代码并在 Node Js 上请求,但出现错误 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">
谢谢大家!)
快递服务器应用代码:
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!'))
与 console.log(h2)
代码屏幕
与console.log($.html());
屏幕工作!
您的 select 或缺少 .
您现在正在查找名为 faq_cat
的标签,该标签不存在。您想要 select 具有 class 名称的元素 faq_cat
使用const h2 = $('.faq_cat').attr('id')
我正在尝试使用 cheerio 解析代码并在 Node Js 上请求,但出现错误 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">
谢谢大家!)
快递服务器应用代码:
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!'))
与 console.log(h2)
代码屏幕
与console.log($.html());
您的 select 或缺少 .
您现在正在查找名为 faq_cat
的标签,该标签不存在。您想要 select 具有 class 名称的元素 faq_cat
使用const h2 = $('.faq_cat').attr('id')