Skip to content

Instantly share code, notes, and snippets.

@DemiKara
Created June 26, 2017 15:03
Show Gist options
  • Save DemiKara/9061d8e59326e32711b1f64bcd6786c2 to your computer and use it in GitHub Desktop.
Save DemiKara/9061d8e59326e32711b1f64bcd6786c2 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import requests
from PIL import Image
from io import BytesIO
search = input("Search for:")
params = {"q": search}
r = requests.get("http://www.bing.com/images/seach", params=params)
print("Check")
soup = BeautifulSoup(r.text, "html.parser")
links = soup.findAll("a", {"class": "thumb"})
print("Check Check")
for item in links:
img_obj = requests.get(item.atrrs["href"])
print("Getting", item.attrs["href"])
title = item.attrs["href"].split("/")[-1]
img = Image.open(BytesIO(img_obj.content))
img.save("./images/" + title, img.format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment