-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomdirect-parser.js
More file actions
executable file
·45 lines (36 loc) · 1.4 KB
/
comdirect-parser.js
File metadata and controls
executable file
·45 lines (36 loc) · 1.4 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let getPrice = async function (text) {
// get price
let regex = /<span class="realtime-indicator--value text-size--xxlarge text-weight--medium">([\s ]+)?([0-9\.]+,[0-9]+)([\s ]+)?<\/span>/gmi;
let match = regex.exec(text);
if(match == null || match[2] ===undefined){
// regex = /<span class="text-size--xxlarge text-weight--medium">([\s ]+)?([0-9\.]+,[0-9]+)([\s ]+)?<\/span>/gmi;
regex = /<meta itemprop="price" content="(?<price>\d+[\.,]\d+)" \/>/gmi;
match = regex.exec(text);
if(match == null || match[1] ===undefined) {
throw new Error("ERROR can not get current price");
}
}
let currentPrice = match[1].replace(",",".");
return currentPrice;
};
let getName = async function (text) {
// get name
/*
<h1 class="headline headline--h1 headline--full-width headline--inline">
DEUTSCHE LUFTHANSA
<span
*/
regex = /headline--inline\">((.|\s|\S)*?)<span/gmi;
match = regex.exec(text);
if(match == null || match[1] ===undefined) {
// second try
regex = /headline headline--h1 headline--full-width headline--inline text-size--medium\">((.|\s|\S)*?)<span/gmi;
match = regex.exec(text);
if(match == null || match[1] ===undefined)
throw new Error("ERROR can not get Name");
}
let name = match[1];
name = name.trim();
return name;
};
module.exports = Object.assign({ getPrice },{getName});