Importing data on website using ImportXML with google sheets

Viewed 132

Trying to import the balance on this website

https://debank.com/profile/0x4e2a7d0e465d8d38aa5a1852d438e60b5832c1b4

The function im using is

=IMPORTXML("https://debank.com/profile/0x4e2a7d0e465d8d38aa5a1852d438e60b5832c1b4","/html/body/div[1]/div/div[2]/div[1]/div[2]/div/div[1]/div[2]")

but then i get a error saying

Error Imported content is empty.

2 Answers

google sheet import formula does not support the scrapping of javascript elements

enter image description here

Alternatively, you can use debank's own API and use this custom function:

Custom Function:

function getTotalBalance(user_id) {
  // replace key if you created your own account 
  var key = 'cee6f36d707cf3dfb48e8d857408ef14ec707efa'; 
  var url_balance = `https://pro-openapi.debank.com/v1/user/total_balance?id=${user_id}`;
  var params = {
    'muteHttpExceptions': true,
    'headers': {
      'accept': 'application/json',
      'AccessKey': key
    }
  };

  return JSON.parse(UrlFetchApp.fetch(url_balance, params).getContentText()).total_usd_value;
}

Formula:

=getTotalBalance("0x4e2a7d0e465d8d38aa5a1852d438e60b5832c1b4", B1)

Where the parameters are the user_id andB1 is a checkbox that would refresh the total balance if toggled.

Output:

output

Note:

  • Simply go to https://open.debank.com/ and register an email to get 10000 units for free.
  • Every balance fetch (toggle on checkbox) will cost you 150 units.
  • If your units get exhausted, you can register another mail and use its new key if you dont want to spend money, or pay for additional units if you want. price
  • You can use my key until it is exhausted. Note that the custom function won't automatically refresh, but you can use the checkbox method to refresh the value, or install a time trigger to refresh it on a specific time (I recommend using the checkbox method above since doing it on trigger and refresh it on intervals might exhaust your units faster than refreshing it manually when needed)

Reference:

Related