def get_image_and_wisdom(self, url): response = requests.get(url) soup = BeautifulSoup(response.text) img = soup.first('div', {'id': 'comic'}).first('img') return img['src'], img['title']
for collection in collections_soup('a'): print '>>>' + base_url + collection['href'] f = urllib.urlopen(base_url + collection['href']) result = f.read() f.close() collection_soup = BeautifulSoup() collection_soup.feed(result) for thumb in collection_soup('td', {'class' : 'thumbs'}): for image in thumb('a'): if string.find(image['href'], 'javascript') == -1 and string.find(image['href'], 'title') == -1: f = urllib.urlopen(base_url + image['href']) result = f.read() f.close() image_soup = BeautifulSoup() image_soup.feed(result) title = image_soup.first('title').contents[0] filename = string.split(title.string, '.JPG')[0] print filename for photo_div in image_soup('div', {'class' : 'photo-image'}): for img in photo_div('img'): print img print filename f = urllib.urlopen(img['src']) result = f.read() f.close() # Replace /tmp/ below with the path to a folder on your hard drive img = open('/tmp/' + filename + '.JPG', 'wb+') img.write(result) img.close()