简体   繁体   中英

Google Sheets - IMPORTXML from livecoinwatch.com (Which XPath?)

I cannot seem to find the correct XPath to get the data from 1h and 24h price change @ https://www.livecoinwatch.com

As far as I can see, the XPaths are;

1h

//*[@id="btchpc"]

24h

//*[@id="btcdpc"]

But, using the syntax (1h);

=IMPORTXML("http://www.livecoinwatch.com/","//*[@id='btchpc']")

Returns an error; "Imported content is empty".

Changing it to

=IMPORTXML("http://www.livecoinwatch.com/","//span[@id='btchpc']")

... doesn't work either.

I have another IMPORTXML function which works pefectly. It's for 24h change as well, from coinpuffs.com;

=IMPORTXML("https://coinpuffs.com/coin/BTC","//span[@id='coin-pct-change-value']")

Sorry if the above sounds completely ridiculous - I've only just started using the IMPORTXML function and I'm not really good at HTML and XML structures.

Thank you!

EDIT#1;

Further investigations are getting me closer to the target. Instead of working out of the front page, I got into the respective coin's page, eg BTC and found the XPaths to the 1h, 24h and also 7d and 30d(!);

1h:

//*[@id="hpc"]

24h:

 //*[@id="dpc"]

7d:

//*[@id="wpc"]

30d:

//*[@id="mpc"]

Now, using the new URL and XPaths, I actually get some results, put they are parsed quite funny;

When I use the syntax (1h); in cell A1

=IMPORTXML("https://www.livecoinwatch.com/price/Bitcoin-BTC","//*[@id='hpc']")

The result gets parsed into cell A3 and B1. What's going on?

So... Found the answer myself.

Had to add "span" to the syntax, ie it looks likes this;

1h

=IMPORTXML("https://www.livecoinwatch.com/price/Bitcoin-BTC","//span[@id='hpc']")

Works!

The page is no valid HTML so it seems google docs is not able to parse it. This however, loads the full table

=IMPORTHTML("http://www.livecoinwatch.com","table",1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM