-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialScrape.js
44 lines (37 loc) · 1.46 KB
/
initialScrape.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
const puppeteer = require('puppeteer');
const moment = require('moment');
const stringify = require('csv-stringify');
const fs = require('fs');
(async () => {
const today = moment();
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.washtenaw.org/3108/Cases');
const [totalCasesTable,
byAgeGroupTable,
bySexTable,
byZipCodeTable,
byRaceTable] = await page.evaluate((today) => {
return Array.from(document.querySelectorAll('.widgetBody table')).map((t) => {
return Array.from(t.tHead.rows).map(r => ['Date', ...Array.from(r.cells).map((c) => c.textContent.trim())]).concat(
Array.from(t.tBodies[0].rows).map(r =>[today, ...Array.from(r.cells).map((c) => c.textContent.trim())])
);
});
}, today);
stringify(totalCasesTable, (err, output) => {
return fs.writeFileSync("data/totalCases.csv", output);
});
stringify(byAgeGroupTable, (err, output) => {
return fs.writeFileSync("data/byAgeGroup.csv", output);
});
stringify(bySexTable, (err, output) => {
return fs.writeFileSync("data/bySex.csv", output);
});
stringify(byZipCodeTable, (err, output) => {
return fs.writeFileSync("data/byZipCode.csv", output);
});
stringify(byRaceTable, (err, output) => {
return fs.writeFileSync("data/byRace.csv", output);
});
await browser.close();
})();