-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (22 loc) · 1.06 KB
/
server.js
File metadata and controls
31 lines (22 loc) · 1.06 KB
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
const puppeteer = require('puppeteer')
const express = require('express');
async function scrape() {
var ret="";
const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox','--disable-dev-shm-usage']})
const page = await browser.newPage()
await page.goto('https://www.hkab.org.hk/hibor/listRates.do?lang=en&Submit=Detail')
const text = await page.evaluate(() => Array.from(document.querySelectorAll("body > table > tbody > tr > td:nth-child(1) > table > tbody > tr > td > table > tbody > tr > td > table > tbody > tr:nth-child(1) > td > table > tbody > tr:nth-child(3) > td:nth-child(1) > table > tbody > tr > td > table > tbody > tr:nth-child(n+4):nth-last-child(n+3) > td"), element => element.textContent));
for(var i=0;i<text.length/2;i++){
console.log(text[2*i]+"\t"+text[2*i+1])
ret = ret+ text[2*i]+"\t"+text[2*i+1];
}
console.log("done");
browser.close()
return ret;
}
const app = express();
app.get('/', async(req, res) => {
const ret=await scrape()
res.send(ret);
});
app.listen(8080, '0.0.0.0');