Created
November 18, 2008 09:25
-
-
Save vagmi/26087 to your computer and use it in GitHub Desktop.
some bug fixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import datetime | |
import os.path | |
from BeautifulSoup import BeautifulSoup | |
dilbert_dir = 'c:\\work\\toons\\dilbert\\' | |
year=2007 | |
start_date=datetime.date(year,1,1) | |
one_day = datetime.timedelta(days=1) | |
current_date = start_date | |
base_url = r'http://www.dilbert.com/fast/' | |
while(current_date.year==year and current_date <= datetime.date.today()): | |
dtfmt=current_date.strftime('%Y-%m-%d') | |
contents=urllib2.urlopen(base_url + dtfmt + '/').read() | |
soup=BeautifulSoup(contents) | |
img_loc=soup.findAll('img')[-1]['src'] | |
print 'downloading ', img_loc, ' as ', dtfmt, '.gif' | |
img=urllib2.urlopen('http://www.dilbert.com/' + img_loc).read() | |
f=open(os.path.join(dilbert_dir,dtfmt+'.gif'),'wb') | |
f.write(img) | |
f.close() | |
current_date= current_date + one_day | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment