任何有 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?
米脂
慕姐4208626
相关分类