Search code examples
google-sheetsweb-scrapingxpathgoogle-sheets-formulacryptocurrency

IMPORTXML Google Sheets


My date source is: https://walletinvestor.com/forecast/achain-prediction

On the website they have three main numbers that I am trying to import to my google spreadsheet (Current Price, 1-Year Forecast, 5-Year Forecast).

In cell C3 I have:

https://walletinvestor.com/forecast/achain-prediction

In cell D3 I have:

=ImportXML(C3, "//div[@class='col-md-4 col-xs-12 np']//div[contains(@class, 'Current Price')]/@href")

I get an error of "Imported content is empty."

My D column is going to be used to import "Current Price" number, my E column is going to be used to import "1-Year Forecast" number, and my F column is going to be used to import "5-Year Forecast" number. I've done a lot of googling and messing around with the IMPORTXML function but I can't seem to get it right.

The closest solution I have came up with so far is to use the following code in K3 to import all 3 numbers:

=TRANSPOSE(IMPORTXML(C3,"//div[@class='col-md-4 col-xs-12 np']//span[@class='bignum']"))

Then I use this code to trim off the "USD" text that it imports:

=LEFT(K3,6)

I would like to clean things up and use one IMPORTXML function to import 1 of the numbers and not require me to have to use the LEFT function to trim off the "USD" text. Can anyone help me figure out how to get this to work properly?


Solution

  • Try this. Regexreplace removes USD:

    =arrayformula(regexreplace(TRANSPOSE(IMPORTXML(C3,"//div[@class='col-md-4 col-xs-12 np']//span[@class='bignum']")),"USD",""))