Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am making a discord bot in javascript. My intent is to visit https://api.chess.com/pub/player/edisonst/stats and somehow parse only the chess_daily last rating, chess_rapid last rating, chess_bullet last rating, chess_blitz last rating, etc. I do not know how to choose only those elements.
Here is my existing code.

const discord = require('discord.js')

const fetch = require('node-fetch');

const client = new discord.Client();
const prefix = '!';

client.once('ready', () =>{
    console.log('Console is online');
});

client.on('message', async message => {
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length);

    let url = "https://api.chess.com/pub/player/" + args + "stats";


})

In my last line of code I arrive at the site that I wish to get the information from, but I don't know how to get just those bits. Thank you for any and all help that I may receive.

question from:https://stackoverflow.com/questions/66053467/sorting-through-html-with-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
934 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use jsdom to "render" page that you get and manipulate it as you would in browser. This way you can select elements and get their contents.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...