Skip to main content

Posts

Showing posts from June, 2022

How to extract images in Python

Image scraping in the part of web scraping and data extraction services in normal data extraction more into text data points but image extraction is more on media side. Image scraping is in two ways.     1. Extract all the images in url     2. Extract only image. EX:  https://www.amazon.com/Gaming-Keyboard-Mechanical-Backlit-Anti-Ghosting/dp/B0B243R1Y9 Want to extract product images from above url. Collect image links from above url import requests import shutil soup = requests.get(link , stream = True ) print (link) #link -> image url image_file_name = "file-name.png" if soup.status_code == 200 : with open (image_file_name , 'wb' ) as f: shutil.copyfileobj(soup.raw , f) print ( 'Image sucessfully Downloaded: ' , image_file_name) count += 1 print (count) else : print ( 'Image Couldn \' t be retrieved' )  We can send folder path to store the images and with threading can download multiple images concurrently.  Reach ou...