【发布时间】:2017-06-05 18:27:15
【问题描述】:
我正在使用节点模块Request。我过去也使用过node-fetch,但request 似乎更好。我希望能够用某个 ID/Class/Span 记录一些东西,你可以命名它。这是我当前记录整个身体的代码。
const request = require('request');
request("https://discord.js.org/#/docs/main/stable/class/GuildMember", (err, response, body) => {
if (err) console.log(err);
console.log(body)
});
我想记录用户提供的任何Property 的内容,假设他们提供bannable 我想记录div#doc-for-bannable.class-prop.class-item 的内容,但我不知道该怎么做。
编辑:
我尝试按照建议使用 Cheerio,但它没有给我任何响应,只是控制台中的一个空格。我尝试的代码是:
request("https://discord.js.org/#/docs/main/stable/class/GuildMember", (err, response, body) => {
if (err) console.log(err);
const $ = cheerio.load(body);
const g = $('docs-page'); // this doesn't work either, after trying '#doc-for-bannable`
const gText = g.text();
console.log(gText)
});
【问题讨论】:
-
看看
cheerio。这正是您所需要的。 github.com/cheeriojs/cheerio -
@KrishnaKalubandi 我编辑了我的原始帖子并解释了我现在遇到的问题。
标签: javascript node.js request node-request