Bonus Lesson: Download Images
Learn how to download images and save them.
We'll cover the following
Images are an integral part of modern web design, enhancing websites’ visual appeal and user experience. In this lesson, we’ll learn how to acquire images from the internet and save them to our local devices. There can be scenarios where we need to download and save images in addition to scraping text data. Let’s learn how to do this in Puppeteer.
Approach
The HTML <img>
element is the fundamental element that is used to embed images into web pages. The src
attribute in the img
element specifies the location where the image is stored. If we can figure out this location from src
attribute via Puppeteer, we can directly download the image from where it is stored. This can be quickly done in Puppeteer by using an appropriate selector to locate the img
element in DOM and then taking the value of src
the attribute.
Implementing the approach
Now, let’s learn to implement this by trying to store the image of the book:
Get hands-on with 1400+ tech skills courses.