Created
April 12, 2015 18:37
-
-
Save vik-y/f98ba5f5154cc5bd13dd to your computer and use it in GitHub Desktop.
Download all images on a webpage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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