d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Javascript Task: Scrape Web Text. > 500fg
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Sep 24 2019 06:23am
Requirements:

* You can use any framework/library you like, as long as it is javascript.
* You don't have to use a framework.

Task: Given an array of codepen.io links ... compile them into a .txt document.

Example:

const inputArray = [
https://codepen.io/WebDevSimplified/pen/EdEjyx
]

Output would yield:

A. https://codepen.io/WebDevSimplified/pen/EdEjyx.html
B. https://codepen.io/WebDevSimplified/pen/EdEjyx.css
C. https://codepen.io/WebDevSimplified/pen/EdEjyx.js

All of the text on A, B, and C would be pasted together on a single .txt document.
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Sep 24 2019 07:29pm
Using Node v 8.11.4
Code
const http = require('https');
const fs = require('fs');

const inputArray = [
'https://codepen.io/WebDevSimplified/pen/EdEjyx',
'https://codepen.io/vcurd/pen/rNBPQWr',
];

inputArray.forEach(url => {
['html', 'css', 'js'].forEach(extension => {
http.get(`${url}.${extension}`, (res) => {
let data = [];
res.on('data', chunk => {
data.push(chunk);
});
;
res.on('end', () => {
fs.writeFile(`${url.substring(19).replace(/\//g, '_')}.txt`,
data,
{ flag: 'a' },
(err) => {
if (err) throw err;
});
});
});
});
})
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll