Skip to content

Instantly share code, notes, and snippets.

@vshivam
Created August 3, 2012 23:54
Show Gist options
  • Select an option

  • Save vshivam/3252815 to your computer and use it in GitHub Desktop.

Select an option

Save vshivam/3252815 to your computer and use it in GitHub Desktop.
Retrieve Latest xkcd
import urllib
def xkcd_latest():
source = urllib.urlopen('http://xkcd.com/').read()
url_start = source.find('img src="http://imgs.xkcd.com/comics/')
start_quote = source.find('"',url_start)
end_quote = source.find('"',start_quote+1)
url=source[start_quote+1:end_quote]
file_name = url[28:end_quote]
print file_name
print url
image_file = urllib.urlretrieve(url, "C:\\Python\\xkcd\\"+file_name)
xkcd_latest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment