I have a table from "Lead rolling actors" from Wikipedia and I want to add some columns to the table with the dates of birth, years active etc for every actor.
It's the first time I use IMPORTXML formula but for Robert Downey Jr I am trying the following:
-Born: =IMPORTXML(G1!,"//span[@class='bday']")
< span class="bday">1965-04-04</ span>
-Years Active: =IMPORTXML(G1!,"//td[@class='infobox-data']")
< td class="infobox-data">1970–present</ td>
In both cases it gives me errors. What am I doing wrong? I looked on https://www.benlcollins.com/spreadsheets/google-sheet-web-scraper/ to get some guidance but I can't find my error.
From your question and showing image, unfortunately, I cannot see the URL of Robert Downey Jr
. But, if the URL is supposed as https://en.wikipedia.org/wiki/Robert_Downey_Jr
, I think that your xpath of //span[@class='bday']
returns 1965-04-04
. But, your xpath of //td[@class='infobox-data']
returns multiple values.
In this answer, the values of 1965-04-04
and 1970–present
are retrieved from the URL of https://en.wikipedia.org/wiki/Robert_Downey_Jr
.
In this sample, 1965-04-04
is retrieved from https://en.wikipedia.org/wiki/Robert_Downey_Jr
.
=IMPORTXML("https://en.wikipedia.org/wiki/Robert_Downey_Jr","//span[@class='bday']")
In this sample, 1970–present
is retrieved from https://en.wikipedia.org/wiki/Robert_Downey_Jr
.
=IMPORTXML("https://en.wikipedia.org/wiki/Robert_Downey_Jr","//td[@class='infobox-data' and ../th[contains(text(),'active')]]")
Robert Downey Jr
, for example, how about checking the URL again? Because when I use the URL of https://en.wikipedia.org/wiki/Robert_Downey_Jr
, your expected values could be retrieved.