Search code examples
google-sheetsgoogle-query-language

XPath queries to scrape data


I'm using Copy XPath from Chrome to create my queries. It works very well but not for this question.

Here is the site I scrape data from.

One query that works (number next to "Senaste NAV-kurs" in table 1)

=IMPORTXML("http://www.di.se/di-fonder/fonddetaljer/?InstrumentId="&1085603;"//*[@id='fund-summary-wrap']/div[1]/dl[2]/dd/text()" )

But when I copy XPath from table with title "AVKASTNING" i'm getting no data, pls help

=IMPORTXML("http://www.di.se/di-fonder/fonddetaljer/?InstrumentId="&1085603;"//*[@id='ctl00_FourColumnWidthContent_ThreeColumnsContent_MainAndSecondColumnContent_fundInfo_fundPerformance_tableFund']/tbody/tr[4]/td[2]/span" )

Solution

  • If you are willing to try it another way, the following will get the "AVKASTNING" table.

    =IMPORTHTML("http://www.di.se/di-fonder/fonddetaljer/?InstrumentId=1085603","table",7)
    

    If you want a specific value from the table use index. The following example gets the second row second column value:

    =index(IMPORTHTML("http://www.di.se/di-fonder/fonddetaljer/?InstrumentId=1085603","table",7),2,2)