Home > front end >  Google Docs IMPORTXML exact data value
Google Docs IMPORTXML exact data value

Time:10-01

first of all: I'm completely new to this, I just started with XML/HTML an hour ago and I tried to import data from a website to work with it in Google Docs/tables. The website uses HTML and I try to import the exact value behind a displayed one and rounded version on the website i.e. for example instead of 86% displayed I want the value 0.8597.

In this example I try to grab the Playoff chances for every NFL team in the 2021 season, recent week, based of FiveThirtyEight's predictions. First off, I import the team names using this formula: =IMPORTXML("https://projects.fivethirtyeight.com/2021-nfl-predictions/"; "//table[@id='standings-table']/tbody/tr/td[@class='team']/span[@class='full']")

After that, I try to import the playoff chances with this formula:

=IMPORTXML("https://projects.fivethirtyeight.com/2021-nfl-predictions/"; "//table[@id='standings-table']/tbody/tr/td[@class='pct div']")

That returns the following:

TEAM Playoff chances
Rams 86%
Buccaneers 83%
... ...

But I want this:

TEAM Playoff chances
Rams 0.8597
Buccaneers 0.82702
... ...

The whole element with the values looks like this, in this case for the Los Angeles Rams (LAR) <td class="pct div" data-team="LAR" data-cat="make_playoffs" data-val="0.8597" style="background-color:rgb(36, 159, 219);color:#000;">86%</td>

Instead of the >86%< I want to receive the data-val="0.8597"

I tried to describe my problem as good as I can, I hope you can understand it. Thanks for anyone reading this or even answering!

-Daxelinho

CodePudding user response:

In your situation, how about the following xpath?

Modified xpath:

//table[@id='standings-table']/tbody/tr/td[@class='pct div']/@data-val

and

//td[@class='pct div']/@data-val

Result:

When the above xpath is used, the following result is obtained.

enter image description here

In this case, the sample formula is =IMPORTXML("https://projects.fivethirtyeight.com/2021-nfl-predictions/", "//td[@class='pct div']/@data-val")

  • Related