js. It is a great tool for testing and recovering web applications. Install it in your terminal using the following command: Bash Copy the code npm install [email protected] You only need the following code to gather all the links to the MIDI files on the Video Game Music Archive page referenced above: JavaScript Copy the code const got = require('got'); const jsdom = require("jsdom"); const { JSDOM } = jsdom; const vgmUrl= tendo/nes'; const isMidi = (link) => { // renvoie false si l'attribut href n'est pas présent if(typeof link.href === 'undefined') { return false } return link.
href.includes('.mid'); }; const noParens = (link) => { // Expression Régulière qui détermine si le texte comporte des parenthèses. const parensRegex = /^((?!\().)*$/; return parensRegex.test(link.textContent); }; (async () => { const response = await got(vgmUrl); const dom = new JSDOM(response.body); // Créée un tableau à partir des éléments HTML pour les filtrer const nodeList = [...dom.window.document.querySelectorAll('a')]; nodeList.filter(isMidi).filter(noParens).forEach(link => { console.log(link.href); }); })(); This code uses the very simple query selector ato access all the hyperlinks on the page, along with a few functions to filter that content and make sure we only get the MIDI files we want.
The filter function noParens()uses a regular expression to exclude all telegram philippines girl MIDI files that contain parentheses: there will be no alternative versions of the same song. Save this code in a file named index.js, and run it with the command node index.jsin your terminal. If you want a more in-depth look at this library, check out the other tutorial I wrote on using jsdom . Cheerio Cheerio is a library similar to jsdom, but it is designed to be more lightweight, making it much faster. It implements a subset of jQuery core, providing an API that many JavaScript developers are familiar with.
Install it with the following command: Bash Copy the code npm install [email protected] The code we need to accomplish this same task is very similar: JavaScript Copy the code const cheerio = require('cheerio'); const got = require('got'); const vgmUrl= ic/console/nintendo/nes'; const isMidi = (i, link) => { // renvoie false si l'attribut href n'est pas présent if(typeof link.attribs.href === 'undefined') { return false } return link.attribs.href.includes('.mid'); }; const noParens = (i, link) => { // Expression régulière qui détermine si le texte comporte des parenthèses const parensRegex = /^((?!\().
The filter function noParens()uses a
-
- Posts: 10
- Joined: Sun Dec 22, 2024 5:32 am