-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrape.js
52 lines (38 loc) · 1.33 KB
/
scrape.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const request = require('request');
const cheerio = require('cheerio');
request('http://codedemos.com/sampleblog/', (error, response, html) => {
if (!error && response.statusCode == 200) {
// enables you to use jQuery like sytax
const $ = cheerio.load(html);
/**
* BASICS
*/
// const siteHeading = $('.site-heading');
// Very large object...
// console.log(siteHeading);
// HTML
// console.log(siteHeading.html());
// Text
// console.log(siteHeading.text());
// Using find...
// const output = siteHeading.find('h1').text();
// Using children...
// const output = siteHeading.children('h1').text();
// Nesting children with next
// const output = siteHeading.children('h1').next().text();
// Child of parent = same
// const output = siteHeading.children('h1').parent().text();
// console.log(output);
/**
* LOOPING
*/
$('.nav-item a').each((i, el) => {
// whatever your second parameter is plug it in with $
// all nav items text
// const item = $(el).text();
// all nav items urls!!
// const link = $(el).attr('href');
// console.log(link);
});
}
});