-
Notifications
You must be signed in to change notification settings - Fork 1
/
download-memebase.py
67 lines (50 loc) · 1.75 KB
/
download-memebase.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from bs4 import BeautifulSoup
import urllib
import os
import sys
import requests
dir = os.path.dirname(os.path.abspath(__file__))
memebase = dir +"\\MemebasePics"
if not os.path.exists(memebase):
os.makedirs(memebase)
#supa za pocetnu
main_url = "http://memebase.cheezburger.com/"
print "Entered Page 1"
r = requests.get(main_url)
data = r.text
supaPocetna = BeautifulSoup(data, "html.parser")
for imglink in supaPocetna.findAll("img", {"class" : "resp-media"}):
mylink = imglink.get("src")
current_comic_src = imglink.get("title")
open_img = urllib.urlopen(mylink)
img_data = open_img.read()
filename = current_comic_src
filename = filename + ".jpg"
filename = filename.replace(':','')
filename = filename.replace('?','')
filename = filename.replace('#','Hashtag')
path = os.path.join(memebase,filename)
with open (path,"wb") as data:
data.write(img_data)
print "Completed download of image:" + filename
#supa za ostale stranice do 10
for url_range in range(2,11):
main_url = "http://memebase.cheezburger.com/page/" + str(url_range)
print "Entered Page " + str(main_url)
r = requests.get(main_url)
data = r.text
supa = BeautifulSoup(data, "html.parser")
for imglink in supa.findAll("img", {"class" : "resp-media"}):
mylink = imglink.get("src")
current_comic_src = imglink.get("title")
open_img = urllib.urlopen(mylink)
img_data = open_img.read()
filename = current_comic_src
filename = filename + ".jpg"
filename = filename.replace(':','')
filename = filename.replace('?','')
filename = filename.replace('#','Hashtag')
path = os.path.join(memebase,filename)
with open (path,"wb") as data:
data.write(img_data)
print "Completed download of image:" + filename