import os, sys, re, urllib, string
reg = re.compile(r"[0-9]{1,3};")
def fix(s):
codes = reg.findall(s)
for i in codes:
s = s.replace(i,'%c'%(int(i.replace('','').replace(';','')))).replace('','').replace('','') #.replace('
','')
return(s)
class IMDb:
def __init__(self, url, Info=False, Details=False, Gallery=False):
if Info == True:
fromInfo = urllib.urlopen(url).read()
self.fromInfo = fix(fromInfo).replace(' / ','').replace(' ',' ').replace('','')
if Details == True:
self.fromDetails = urllib.urlopen(url + 'plotsummary').read()
if Gallery == True:
self.fromGallery = urllib.urlopen(url + 'photogallery').read()
def Galleries(fromGallery, page='0'):
in_gallery = re.compile('"(photogallery.*?|/gallery/.*?)">
(.*?) more')
Gallery = []
Thumbs = []
for a in in_gallery.findall(fromGallery):
Gallery.append(a[0]) # Gallery names
thumbs = urllib.urlopen(url + a[0][:-1] + page).read() # open all gallery pages
gallery = in_gallery.findall(thumbs) # find thumbs for 1st Gallery page of each Gallery
for a in gallery:
Thumbs.append(a[1].replace('th-','')) # changes Thumb images to full-size Images
pgleft = in_pgLeft.findall(thumbs) # parse how many thumbs are left
for a in pgleft:
pgLeft = int(a) / 12 # how many pages are in each gallery
return Gallery, Thumbs
num = '0'
url = 'http://www.imdb.com/title/tt0315824/'
imdb = IMDb(url, Gallery=True)
gal, thumb = Galleries(imdb.fromGallery, page=num)
print gal