安装依赖:
npm install superagent cheerio --save
同步代码:
const superagent = require('superagent')
const cheerio = require('cheerio')
const fs = require('fs')
function getNews() {
return new Promise((resolve, reject) => {
superagent.get('https://a.b.c.cn/').end((err, data) => {
if (err) {
reject('error')
} else {
const $ = cheerio.load(data.text)
var lst = []
$('#blk_cjkjqcfc_011 a').each((index, item) => {
var tex = $(item).text()
if (tex && !tex.endsWith('|')) {
lst.push(tex.replaceAll('\n', ''))
}
})
resolve(lst)
}
})
})
}
async function main() {
var res = await getNews()
console.log(res)
}
main()
标签:tex,const,NodeJS,cheerio,lst,爬取,superagent,var
From: https://www.cnblogs.com/engure/p/17135893.html