简体   繁体   English

使用 axios/cheerio 制作网页抓取工具; 无法弄清楚其余的功能

[英]Making a webpage scraper using axios/cheerio; can't figure out the rest of the function

anyone with axios/cheerio experience can you answer this question please?任何有 axios/cheerio 经验的人都可以回答这个问题吗?

I'm trying to make a scraper but having difficulty making it get a selected div我正在尝试制作一个刮板,但很难让它获得选定的div

the html section is like so: 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>

Scraper Code:刮板代码:

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);
});

outputs:输出:

7.3.2
ISC
83.8 kB
51
github.com/npm/node-semver#readme
Gitgithub.com/npm/node-semver
6 months ago

How would I get the 7.2.3 from this output?我如何从这个输出中得到7.2.3

That class looks like it might change.该课程看起来可能会发生变化。 I would do:我会做:

$('h3:contains("Version") + p').text()
$('._702d723c').each(function (i, e) {
  console.log($(e).find("p").html());
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在制作一个图像板,无法弄清楚链接引用 - I'm making an imageboard and can't figure out link quoting 做个西蒙游戏,不知道哪里错了 - Making a Simon Game, can't figure out what is wrong 无法弄清楚为什么我的标题的其余部分不会显示 - Can't figure out why the rest of my header will not show 获得了90%的JavaScript代码 - 无法弄清楚其余部分 - Got 90% of the JavaScript code - can't figure out the rest Axios &amp; Cheerio - 不能选择多于一个表格行 - Axios & Cheerio - can't select more than one table row 我尝试为 createUser 创建一个可调用的函数,但是我在运行它时遇到了一个错误,我不知道为什么 - I tried making a callable function for createUser but I am getting an error wen I run it and I can't figure out why 刮板不使用cheerio的jQuery返回任何值 - Scraper not returning any values with jquery using cheerio 使用Cheerio和Response for Node Web抓取工具,将响应函数结果传递给视图 - Using Cheerio and Response for Node web scraper, passing response function result to the view 如何使用 axios、reactjs 和 Cheerio 从此网页中提取此特定元素 - How do I extract this particular element from this webpage using axios, reactjs, and cheerio Javascript:使用for循环和子字符串的递归函数示例-无法弄清楚我要去哪里 - Javascript: Example of recursive function using for loops and substring - can't figure out where I'm going wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM