I am trying to scrape data from the following website: Morningstar (https://www.morningstar.nl/nl/funds/snapshot/snapshot.aspx?id=F00000QIPC)
I want to scrape the EUR 20,66
, but only display the '20,66'. I Use the following code:
function import1() {
var html, content = '';
var response = UrlFetchApp.fetch("https://www.morningstar.nl/nl/funds/snapshot/snapshot.aspx?id=F00000QIPC");
if (response) {
html = response.getContentText();
if (html) content = html.match(/<td class="line text">(.*?)<\/td>/)[1];
Logger.log(content)
}
return content;
}
Displayed value is:
EURÂ 20,66
I tried to add \d
to only show values:
if (html) content = html.match(/<td class="line text">(\d.*?)<\/td>/)[1];
but somehow it displays a different value:
1,09%
it doesn't seem to recognize the 20,66
as a value or something. I have tried different things where it would display EUR20,
but never found something to remove the EUR
(I cannot replicate this scenario again sadly)
Any help solving this issue would be greatly appreciated!
It seems like you want to match EUR
and then a number after a variable amount of whitespace.
You may use
\s*EUR\s+(\d[\d,]*)
instead of .*
.
Details
\s*
- 0 or more whitespacesEUR
- a literal text\s+
- 1+ whitespaces(\d[\d,]*)
- Capturing group 1: a digit followed with 0 or more commas or digits.