I am trying to parse data from the following website (https://www.fundsquare.net/security/information?idInstr=275136)
I want to display the price of the fund in Google sheets. However, when using the 'importxml' function I get an error that the "imported content is empty". Anybody know what I can do to fix it?
Ways I tried the function:
=IMPORTXML("https://www.fundsquare.net/security/summary?idInstr=275136" ,"//*[@class ='surligneorange']" )
=IMPORTXML("https://www.fundsquare.net/security/information?idInstr=275136" , "//*[@id='content']/table[2]/tbody/tr/td[3]/span[1]")
=IMPORTXML("https://www.fundsquare.net/security/information?idInstr=275136" , "//*[@id='content']//span[1]")
I keep on getting the same error. When looking for this error I get the difference between static and dynamic data. This data changes so I guess its dynamic but i'm not sure how that would impact the formula.
I have been trying some things with script editor but no success. Also trying something with RegExp but couldn't get any further than the examples. My knowledge of scraping is limited so any tips and tricks when trying to parse data is greatly appreciated! Any help would be greatly appreciated!
Edit: Within script editor I tried the following code:
function importdata() {
var found, html, content = '';
var response = UrlFetchApp.fetch("https://www.fundsquare.net/security/information?idInstr=275136");
if (response) {
html = response.getContentText();
if (html) content = html.match(/<span class="surligneorange">(.*)<\/span>/)[0];
}
Logger.log(content);
}
This gives me the following log output:
[20-06-05 07:44:58:529 PDT] <span class="surligneorange">31.15 EUR</span> <span style="color:#DD0000;text-align:left;padding:4px 0;"> -0.67 % <img src="/images/share/variationNegative.gif" style="vertical-align:middle;"/></span></td></tr></table><div id="onglet"><a href="/security/documents?idInstr=275136">Documents</a><a href="/security/eusd?idInstr=275136">Taxes</a><a href="/security/histo-divid?idInstr=275136">Dividends</a><a href="/security/histo-prices?idInstr=275136">Hist. Prices</a><a href="/security/price?idInstr=275136">Price</a><a href="/security/order-ref-data?idInstr=275136">Order Ref. Data</a><a class="selected" href="/security/information?idInstr=275136">Security Information</a><a href="/security/summary?idInstr=275136">Overview</a><br class="clear_r"/></div><div id="blocresume"><table class="portlet100pct" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="portletleft50pct"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="portletBordGris"><div style="position: relative; left: 1px;" class="bloctitle"><img src="/Fundsquare/images/share/x.gif" border="0" height="1" width="1" /></div><DIV class="bloctitle" style="position: relative; top: -21px; right: 1px;"><span style="top: 3px;" >General information</span>
The value 31.15 is what I want to scrape. How can I get this value in my spreadsheet?
Edit 06/06 10:14: further questions
Could you please help me understand what you changed. What exactly is the difference between what I tried to match and what you matched.
mine:
if (html) content = html.match(/<span class="surligneorange">(.*)<\/span>/)[0];
yours:
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*?<\/span>/)[1];
and:
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*<\/span>/)[1];
What is the difference between my [0] and your [1]. is it that you only request the first value?
What is the difference between my .* and your ([\d.]*).* or [\d.]*).*????
My knowledge from javascript is not so good so I am unsure what it does. Thanks for the help!