[英]Making a webpage scraper using axios/cheerio; can't figure out the rest of the function
任何有 axios/cheerio 经验的人都可以回答这个问题吗?
我正在尝试制作一个刮板,但很难让它获得选定的div
html 部分是这样的:
<div class="_702d723c dib w-50 bb b--black-10 pr2">
<h3 class="c84e15be f5 mt2 pt2 mb0 black-50">Version</h3>
<p class="f2874b88 fw6 mb3 mt2 truncate black-80 f4">7.3.2</p>
</div>
刮板代码:
const cheerio = require("cheerio");
const axios = require("axios");
let NPMJS = `https://www.npmjs.com/package/semver`;
axios.get(NPMJS).then((response) => {
let $ = cheerio.load(response.data);
$('._702d723c').filter(function () {
var data = $(this);
let version = data.children().first().next().text()
console.log(version)
})
}).catch(function (e) {
console.log(e);
});
输出:
7.3.2
ISC
83.8 kB
51
github.com/npm/node-semver#readme
Gitgithub.com/npm/node-semver
6 months ago
我如何从这个输出中得到7.2.3
?
该课程看起来可能会发生变化。 我会做:
$('h3:contains("Version") + p').text()
$('._702d723c').each(function (i, e) {
console.log($(e).find("p").html());
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.