I tried downloading images from bing to a directory but due to some reason the code just executes and gives me nothing.. not even an error.. I used the user-agent HTTP as well.. but it still doesnt seem to be working.. What should i do?
from bs4 import BeautifulSoup
import requests
from PIL import Image
from io import BytesIO
url = 'https://www.bing.com/search'
search = input("Search for: ")
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101
Firefox/80.0'}
params = {"q": search}
r = requests.get(url, headers=headers, params=params)
soup = BeautifulSoup(r.text, "html.parser")
links = soup.findAll("a", {"class": "thumb"})
for item in links:
img_obj = requests.get(item.attrs["href"])
print("Getting", item.attrs["href"])
title = item.attrs["href"].split("/")[-1]
img = Image.open(BytesIO(img_obj.content))
img.save("./scraped_images/" + title, img.format)
To get all images, you need to add
/images
to the link. Here's an example with modifications to your code: