Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- # owahhPics.py - Downloads images from the website.
- import requests, os, bs4
- url = 'http://owaahh.com/exploreturkana-photo-essay'
- os.makedirs('owaahTurkana', exist_ok= True)
- while url.startswith('http://owaahh.com'): # deleted the not
- # TODO: Download the page.
- print('Downloading page %s...' % url)
- res= requests.get(url)
- res.raise_for_status()
- soup = bs4.BeautifulSoup(res.text, 'html5lib')
- # TODO: Find the URL of the blog image.
- picElem = soup.select('.entry-content img')
- if picElem == []:
- print('Could not find image.')
- else:
- linksHere = len(picElem)
- for i in range(linksHere):
- picUrl = picElem[i].get('src')
- # Download the image.
- print('Downloading image %s...' % (picUrl))
- #picUrl = picElem[i]
- res = requests.get(picUrl)
- res.raise_for_status()
- # TODO: Save the image to ./xkcd.
- imageFile = open(os.path.join('owaahTurkana', os.path.basename(picUrl)), 'wb')
- for chunk in res.iter_content(100000):
- imageFile.write(chunk)
- imageFile.close()
- print('Done.')
Advertisement
Add Comment
Please, Sign In to add comment