Skip to content

Commit fd22f0a

Browse files
author
code-reaper08
committed
Functionality enhanced and white space trimmed
1 parent 77707ff commit fd22f0a

File tree

1 file changed

+33
-86
lines changed

1 file changed

+33
-86
lines changed

scrape.js

Lines changed: 33 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,34 @@
1-
const request = require('request');
2-
const cheerio = require('cheerio');
3-
4-
request('https://github.com/code-reaper08/Know-ASCII/blob/main/README.md', (error,response,html) =>{
5-
if(!error && response.statusCode == 200) {
6-
const $ = cheerio.load(html);
7-
const linkObjects = $('#readme > article').children().find('a');
8-
const links = [];
9-
linkObjects.each((index, element) => {
10-
links.push({
11-
// text: $(element).text(),
12-
href: $(element).attr('href'),
13-
});
14-
});
15-
const len = links.length;
16-
// console.log(len);
17-
// console.log(links);
18-
// var arrayLength = myStringArray.length;
19-
for (let i = 0; i <len ; i++) {
20-
// console.log("loop running")
21-
const hrefs = links[i].href;
22-
request(hrefs,(error,response,html) => {
23-
if(!error && response.statusCode == 200) {
24-
console.log(hrefs,' Success');
25-
}
26-
else if(!error && response.statusCode != 200) {
27-
console.log(hrefs,' Failure');
28-
}
29-
})
30-
}
1+
const request = require("request");
2+
const cheerio = require("cheerio");
3+
4+
request(
5+
"https://github.com/code-reaper08/MarkdownAssistant/blob/main/README.md",
6+
(error, response, html) => {
7+
if (!error && response.statusCode == 200) {
8+
const $ = cheerio.load(html);
9+
const linkObjects = $("#readme > article").children().find("a");
10+
const links = [];
11+
linkObjects.each((index, element) => {
12+
links.push({
13+
// text: $(element).text(),
14+
href: $(element).attr("href"),
15+
});
16+
});
17+
const len = links.length;
18+
// console.log(len);
19+
// console.log(links);
20+
// var arrayLength = myStringArray.length;
21+
for (let i = 0; i < len; i++) {
22+
// console.log("loop running")
23+
const hrefs = links[i].href.replace(/\s\s+/g, "");
24+
request(hrefs, (error, response, html) => {
25+
if (!error && response.statusCode == 200) {
26+
console.log(hrefs, " Success");
27+
} else if (!error && response.statusCode != 200) {
28+
console.log(hrefs, " Failure");
29+
}
30+
});
31+
}
3132
}
32-
});
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
// const request = require('request');
66-
// const cheerio = require('cheerio');
67-
68-
// request('https://github.com/code-reaper08/Know-ASCII/blob/main/README.md', (error,response,html) =>{
69-
// if(!error && response.statusCode == 200) {
70-
// const $ = cheerio.load(html);
71-
72-
// //const readmebox = $('#readme > article');
73-
// $('#readme > article').each((i,el) => {
74-
// const item = $(el).text();
75-
// const link = $(el).find('a').attr('href');
76-
// console.log(item);
77-
// // console.log(link);
78-
// })
79-
80-
// //console.log(readmebox.find('a').attr('href'));
81-
// // console.log(reponame.text());
82-
// // const repofiles = reponame.find('a').attr('href');
83-
// // console.log(repofiles);
84-
85-
// }
86-
87-
// });
33+
}
34+
);

0 commit comments

Comments
 (0)