1

Google sheets is giving me some trouble in retrieving span style attributes. I am trying to scrape a site (actually this) to grab some icon images for my spreadsheet. Below in red is one such example image, outlined. Below that is the source HTML I would like to grab it from.

Highlighted in red is an example image I would like to grab

The source it's coming from

I am able to use IMPORTHTML to retrieve information like the names of the characters in a list displayed on the website, but I am having some issues retrieving their icon. Interestingly, the icons for these characters in their list are all jumbled up; if you try to build your icon database based on the index in the list like how the "Fighters" page on the same site is set up, then you will end up with a lot of inaccuracies.

For instance, using the index of the item in the list, if you try to build a list of image urls and import the images that way, the list will be incomplete, and the images will not be correct. The images for "Meowth" may be the image for "Vulpix", etc, depending on the format of the query. Example below:

Mistakes in image import

The formula that I was using for the above result was the following:

=ARRAYFORMULA(IMAGE("https://www.smashbros.com/assets_v2/img/item/pokemon_sub"&A:A&".png"))

It is imperfect because there are multiple ways that the images are named on the website. for instance:

https://www.smashbros.com/assets_v2/img/item/pokemon_sub##.png https://www.smashbros.com/assets_v2/img/item/pokemon_list##.png https://www.smashbros.com/assets_v2/img/item/pokemon_main##.png

To make matters worse, the "##" isn't the index number reliably...

So it looks like the best be would be to scrape the XML of the page and grab the image URLs from the span tag's style attribute. I figured that I could do that using IMPORTXML but I have not had any success. It usually says that "Error: Imported content is empty" but I'm fairly certain that I have the correct xpath...

Here is my query:

=IMPORTXML("https://www.smashbros.com/en_US/item/pokemon.html", "//span[@class='item-pokemon-mainslide__img-thumb']/@style")

Interestingly (at least to me) it comes up with an error. Even if I try to find all the divs of a certain class it doesn't work...

Example:

=IMPORTXML("https://www.smashbros.com/en_US/item/pokemon.html", "//div[@class='item-pokemon-mainslide__item js-pokemon-slide']")

The expected output for the above would be a list of creatures that appear on the web page.

Can anyone help me with this error, or is referencing elements based on attribute value just impossible in Sheets? Criticism welcome, please let me know if there is an easier way to do this!

Here is a link, it would be the "Pokémon" tab, I can adopt and possible solution to the rest of the sheets:

https://docs.google.com/spreadsheets/d/1NLCKhBduJsZBY9tiwSC955duRN15MC1qiWhtVuSx3nM/edit?usp=sharing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.