0

I have tried this, but I get three dots

=IMPORTXML("https://covid19.sabah.digital/covid19/","//span[@class='number-last_updated']")

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 1
    I think this text is coming from a JS file therefore it is impossible to query it by using `importxml`. – Marios Oct 19 '20 at 16:47
  • Does this answer your question? [Google Sheets importXML Returns Empty Value](https://stackoverflow.com/questions/61470783/google-sheets-importxml-returns-empty-value) – Rafa Guillermo Oct 20 '20 at 07:20
  • =IMPORTXML("https://covid19.sabah.digital/covid19/","//div[@class='card-header font-weight-bold']") – Chris Eddy Oct 20 '20 at 07:27
  • But this one have no problem to extract.. – Chris Eddy Oct 20 '20 at 07:27
  • or maybe..cannot extract data that is not static.. – Chris Eddy Oct 20 '20 at 07:51
  • I proposed a workaround as an answer. Could you please confirm it? But I'm not sure whether that is the same direction with you. So if that was not useful for your situation, I apologize. – Tanaike Oct 20 '20 at 23:05

1 Answers1

0

When I saw the HTML data, it seems that the last updated date is displayed by Javascript. By this, unfortunately, the value cannot be directly retrieved with IMPORTXML. This has already been mentioned in the comments.

When I saw the HTML data again, I noticed that the information of date is included in https://data.covid19.sabah.digital/global.json. From this data, how about retrieving the last updated date? In this answer, as a workaround, in order to retrieve the last updated value, I would like to propose to retrieve the data using the following sample formula.

Sample formula:

=TEXT(MAX(ARRAYFORMULA(DATEVALUE(REGEXEXTRACT(QUERY(IMPORTDATA(A1),"SELECT Col1 WHERE Col1 contains 'date'"),"\d{4}-\d{1,2}-\d{1,2}"))))+1,"yyyy-MM-dd")
  • In this formula, please put the URL of https://data.covid19.sabah.digital/global.json to the cell "A1".
  • The flow of this formula is as follows.
    1. Retrieve the JSON data using IMPORTDATA.
    2. Retrieve the data values from the retrieved data using QUERY.
    3. Convert the text to the serial number using DATEVALUE.
    4. Retrieve the max value using MAX.
      • It seems that when this value is added by 1, it is the updated date.
      • If you don't need this, please remove +1 from the formula.
    5. Convert the serial number to the text using TEXT.

Result:

enter image description here

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165