IMPORTXML table with alternating rows

556 views Asked by At

I would like to use the Google Sheet IMPORTXML function to import only the '1B' column from this Fangraphs page.

I am able to use this function:

=importxml("http://www.fangraphs.com/statsd.aspx?playerid=9166&position=C&type=1&gds=&gde=&season=2015", "//tr[@class='rgRow']/td[10]")

to import EVERY OTHER row in the table, because the table is split into two classes of 'rgRow' and 'rgAltRow.' However, I need to import every row.

I would also like to import all the way down the list, not stopping at each new header.

How could this be done? I would rather not use multiple IMPORTXML functions in order to keep the page running quickly.

1

There are 1 answers

0
Michael Oryl On BEST ANSWER

Assuming this is an xpath query, try this:

=importxml("http://www.fangraphs.com/statsd.aspx?playerid=9166&position=C&type=1&gds=&gde=&season=2015", "//tr[@class='rgRow']/td[10] | //tr[@class='rgAltRow']/td[10]")

Note the addition of the | character (for 'or') and the second expression of //tr[@class='rgAltRow']/td[10]