Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload from EXPLOSM.net Comics Script [Python]
    primarykey
    data
    text
    <p>So I wrote this short script (correct word?) to download the comic images from explosm.net comics because I somewhat-recently found out about it and I want to...put it on my iPhone...3G.</p> <p>It works fine and all. urllib2 for getting webpage html and urllib for image.retrieve()</p> <p><strong><em>Why I posted this on SO: how do I optimize this code? Would REGEX (regular expressions) make it faster? Is it an internet limitation? Poor algorithm...?</em></strong></p> <p>Any improvements in speed or <strong><em>general code aesthetics</em></strong> would be greatly appreciated "answers".</p> <p><i>Thank you.</i></p> <p><i>--------------------------------CODE----------------------------------</i></p> <pre><code>import urllib, urllib2 def LinkConvert(string_link): for eachLetter in string_link: if eachLetter == " ": string_link = string_link[:string_link.find(eachLetter)] + "%20" + string_link[string_link.find(eachLetter)+1:] return string_link start = 82 end = 1506 matchingStart = """&lt;img alt="Cyanide and Happiness, a daily webcomic" src="http://www.explosm.net/db/files/Comics/""" matchingEnd = """&gt;&lt;/""" link = "http://www.explosm.net/comics/" for pageNum in range(start,start+7): req = urllib2.Request(link+`pageNum`) response = urllib2.urlopen(req) page = response.read() istart1 = page.find(matchingStart) iend1 = page.find(matchingEnd, istart1) newString1 = page[istart1 : iend1] istart2 = newString1.find("src=")+4 iend2 = len(newString1) final = newString1[istart2 +1 : iend2 -1] final = LinkConvert(final) try: image = urllib.URLopener() image.retrieve(final, `pageNum` + ".jpg") except: print "Uh-oh! " + `pageNum` + " was not downloaded!" print `pageNum` + " completed..." </code></pre> <p><i>By the way, this is Python 2.5 code, not 3.0 but you bet I have all the features of PYthon 3.0 greatly studied and played around with before or right after New Year (after College Apps - YAY! ^-^)</i></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload