-
Notifications
You must be signed in to change notification settings - Fork 0
/
cZelda.py
36 lines (27 loc) · 990 Bytes
/
cZelda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! python3
#downloadXkcd.py - Downloads most recent pictures of Zelda
import requests, os, bs4
url = 'https://twitter.com/CuriousZelda' # starting url
os.makedirs('curious_zelda', exist_ok = True) # store pics in ./curious_zelda
# Download the page
print('Downloading kitty pics')
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text)
# Find the URL of the comic image.
picDiv = soup.select('.js-adaptive-photo ')
for pic in picDiv:
picUrl = pic.get('data-image-url')
if picUrl == None:
print('Could not find Zelda')
else:
# Download the image
print('Downloading image %s' % (picUrl))
res = requests.get(picUrl)
res.raise_for_status()
# Save the image to ./curious_zelda
imageFile = open(os.path.join('curious_zelda', os.path.basename(picUrl)), 'wb')
for chunk in res.iter_content(100000):
imageFile.write(chunk)
imageFile.close()
print('Done.')