Try:
import requests from bs4 import BeautifulSoup url = "http://www.pythonscraping.com" html = requests.get(url, stream=True) if html.status_code == 200: bsObj = BeautifulSoup(html.content, 'html.parser') imageLocation = bsObj.find("a", {"id":"logo"}).find("img")["src"] image = requests.get(imageLocation) if image.status_code == 200: with open('img.jpg', 'wb') as out_file: out_file.write(image.content) else: print(f'Problem fetching image status code: {image.status_code}') else: print(f'Problem fetching {url} status code: {html.status_code}')-- Edit Modified 2nd request, should check status code --