Skip to content

Instantly share code, notes, and snippets.

@vik-y
Created April 12, 2015 18:37
Show Gist options
  • Select an option

  • Save vik-y/f98ba5f5154cc5bd13dd to your computer and use it in GitHub Desktop.

Select an option

Save vik-y/f98ba5f5154cc5bd13dd to your computer and use it in GitHub Desktop.
Download all images on a webpage
import requests
from BeautifulSoup import BeautifulSoup
r = requests.get('http://<url>')
while r.status_code!=200:
r = requests.get('http://<urL>')
soup = BeautifulSoup(r.text)
images = soup.findAll('img')
for i in range(0, len(images)):
url= 'http://<url>'+images[i]['src']
img = requests.get(url)
while img.status_code!=200:
img = requests.get(url)
with open(str(i)+".jpg", 'wb') as test:
test.write(img.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment