Home > Back-end >  Google Sheets - importXml Xpath not working
Google Sheets - importXml Xpath not working

Time:01-17

I'm trying to create a worksheet on google drive in which to fill some cells with automatic values taken at each refresh from a web page. The page is this: https://pro.youngplatform.com/pairs/ I would like to automatically take the price values of the various cryptocurrencies in €

I found that this can be done through googlesheet's importXml function which requires the site link and the xPath of the html tag to be retrieved as parameters.

Now, on another site I used this formula and it worked: = IMPORTXML ("https://coinmarketcap.com/it/currencies/basic-attention-token"; "/ html / body / div / div / div [1] / div [2] / div / div [1] / div [2] / div / div [2] / div [1] / div / span ")

In the page I am trying now, however, I have tried these two versions but neither of them work. 1.=IMPORTXML("https://pro.youngplatform.com/pairs";"/html/body/div[1]/div/div/div/div[3]/div[2]/div/div/div[2]/div[1]/a/div/div[2]/p[2]")

2.=IMPORTXML("https://pro.youngplatform.com/pairs";"//div[@class='sc-cKRKFl kSUooD pair-row']/a/div/div[2]/p[2]")

The data that I want to retrieve in the web page is this one one the screen: Image

and the html is:

<div >
  <div  style="display: flex; box-sizing: border-box; flex-direction: column; justify-content: space-between; padding: 24px;">
    <div > 
      <div style="width: 100%; display: flex; flex-direction: row; padding-top: 16px;">
        <p color="var(--dark-gray-2)" font-family="euclid" font-size="medium" type="label"  style="margin-top: auto; margin-bottom: auto;">Ultimo prezzo</p>
        <div style="margin-left: auto; display: flex; flex-direction: row;">
          <p color="var(--white)" font-family="euclid" font-size="medium" type="label" >37.186,79 EUR</p>
          <p color="var(--dark-gray-1)" font-family="euclid" font-size="xsmall" type="paragraph"  style="margin-left: 3px;">37.186,79 €</p> 
        </div>
      </div>
    </div>
  </div>
</div>

I want to take the value inside: <p color="var(--dark-gray-1)" font-family="euclid" font-size="xsmall" type="paragraph" style="margin-left: 3px;">37.186,79 €</p>

Thanks for the help

CodePudding user response:

JavaScript content is not supported by any IMPORT formulae. the best course of action would be to find a different source for your scrapping.

CodePudding user response:

First you will need to add script to your Google Sheet.

How to add script to your G/S https://developers.google.com/apps-script/guides/sheets/functions#creating_a_custom_function

Add this script https://github.com/bradjasper/ImportJSON/blob/master/ImportJSON.gs

After these steps are done you can use this formula:

=index(ImportJSON("https://bff.youngplatform.com/market/get-chart-data?baseCurrency=BTC&quoteCurrency=EUR&limit=1",""),2,5)

This will give you the first pair BTC to EUR. For the second pair Change the url to which pair you need on the screenshot you needed ETH to BTC. so it will be:

=index(ImportJSON("https://bff.youngplatform.com/market/get-chart-data?baseCurrency=ETH&quoteCurrency=BTC&limit=1",""),2,5)

Let me know if that what are you looking for.

  •  Tags:  
  • Related