Pages

Sunday, March 3, 2019

IMPORTXML function to get images from websites

Image extraction using IMPORTXML formula


In this article we’ll work through a similar scenario and explain how to use the IMPORTXML  function of Google Sheets to import how many likes our Facebook page has and how many followers our Twitter page has. This function doesn't update on its own by default so we've written a script that we'll explain how to adapt to ensure your data is kept up to date. 


The syntax of the ImportXML function is:

=IMPORTXML(URL, query)


URL
The URL of the page to examine, including protocol (e.g. http://). The value for URL must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.

query
The XPath query to run on the data given at the URL. Each result from the XPath query is placed in its own row of the spreadsheet.

In this blog post it is expected to explain how to import images from websites.

To take images from webites you have to use IMPORTXML function as follows in google sheet.

=IMPORTXML(A2,"//img[@class='dynamic-image']/@src")

Above function the word "dynamic-image" has used to extract images from websites.This is vary when it comes to different sites.

We use following URL to grab images from web site.

https://www.banggood.com/Soloop-328pcs-21-Polyolefin-Halogen-Free-Heat-Shrink-Tube-Sleeving-5-Color-8-Size-p-969574.html?rmmds=flashdeals&cur_warehouse=CN


image 01

This is the web site we use to extract the images to google sheet;

https://www.banggood.com/Soloop-328pcs-21-Polyolefin-Halogen-Free-Heat-Shrink-Tube-Sleeving-5-Color-8-Size-p-969574.html?rmmds=flashdeals&cur_warehouse=CN

To extract the image from the above website we used following google sheet function;

=IMPORTXML(A2,"//img[@class='dynamic-image']/@src")

according to the above function word 'dynamic-image' has been used as a key word to extract image.This can be extracted from the page source.To get the page source right click on the website and then select the view source from the menu.Then you can select desired word easily.Please see below image,it will show you how we select word 'dynamic-image' for our image extraction formula.


image 02

Summery
Following formulas had been used to fill shown table in image 01.


Link to deal -
https://www.banggood.com/Soloop-328pcs-21-Polyolefin-Halogen-Free-Heat-Shrink-Tube-Sleeving-5-Color-8-Size-p-969574.html?rmmds=flashdeals&cur_warehouse=CN

Website Name -
=REGEXEXTRACT(A2,"\.(.*?)\.")

Item title -
=IMPORTXML(A2,"//strong[@class='title_strong']")

Item Price -
=IMPORTXML(A2,"//div[@class='item_now_price']")

Image URL extraction formula -
=IMPORTXML(A2,"//img[@class='dynamic-image']/@src")

Image -
=image(E2)













1 comment:

  1. I read that Post and got it fine and informative. Please share more like that... Extract images from pdf

    ReplyDelete

Find records in multiple sheets

This lesson will explain to you how to use query function to search specific record from multiple sheets. According to our example we h...

Contact Form

Name

Email *

Message *