Search code examples
htmlgoogle-sheetsweb-scrapingxpathgoogle-sheets-formula

importxml xpath in Google sheets


I need a some help in getting a ImportXML command to return the result I'm looking for. I'm using Google Sheets. This is the website: https://www.foresteu.com/butorajtok-es-tartozekaik/tomorfa/trieste/10000520000-tomorfa-trieste-116x146mm-mez

This xpath works, but it is way too long: //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][2] | //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][3] | //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][4] | //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][5] | //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][6] | //div[contains(@class, 'col-xs-120 nopad')]/div[contains(@class, 'col-xs-120 nopad')][7]

Can i make it shorter? I can't find a shorter xpath which works.


Solution

  • How about this xpath? I think that there might be more simple xpath. So please think of this as one of several answers.

    Modified xpath:

    //div[@class='col-xs-120 nopad'][./span]
    
    • https://www.foresteu.com/butorajtok-es-tartozekaik/tomorfa/trieste/10000520000-tomorfa-trieste-116x146mm-mez is put in "A1".
      • Formula is =IMPORTXML(A1,"//div[@class='col-xs-120 nopad'][./span]")
    • //div[@class='col-xs-120 nopad'] means div that class is col-xs-120 nopad.
    • [./span] means div which have span under div.

    Result:

    enter image description here

    If this was not what you want, I'm sorry.