-
Notifications
You must be signed in to change notification settings - Fork 8
/
scrape_genus.js
35 lines (29 loc) · 1002 Bytes
/
scrape_genus.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
var fs = require('fs')
, cheerio = require('cheerio')
, log = require("./log").log;
const BASE_PATH = "./birds-kb/";
function genusToCSV() {
//Loop through files in birds-kb.
//Load content.
//Extract: genus
//Extract: family
//Extract: title
//Save to File
var files = fs.readdirSync(BASE_PATH);
var asCSV = "";
var counter = 0;
for (var i = 0; i < files.length; i++) {
var data = fs.readFileSync(BASE_PATH + files[i], "utf8");
var $ = cheerio.load(data);
let family = $('td:contains("Family") ~ td').children("a").text().trim()
let genus = $('td:contains("Genus") ~ td').children("a").text().trim()
let order = $('td:contains("Order") ~ td').children("a").text().trim()
var title = $("h1").text();
asCSV += `${title},${family},${order},${genus}\n`
}
fs.writeFile('genus.csv', asCSV, function (err) {
if (err) throw err;
console.log('It\'s saved!');
})
}
genusToCSV()