Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 94221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:28:03+00:00 2026-05-10T23:28:03+00:00

So I wrote this short script (correct word?) to download the comic images from

  • 0

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.

It works fine and all. urllib2 for getting webpage html and urllib for image.retrieve()

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…?

Any improvements in speed or general code aesthetics would be greatly appreciated ‘answers’.

Thank you.

——————————–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 = '''<img alt='Cyanide and Happiness, a daily webcomic' src='http://www.explosm.net/db/files/Comics/''' matchingEnd = '''></''' 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...' 

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! ^-^)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:28:03+00:00Added an answer on May 10, 2026 at 11:28 pm

    I would suggest using Scrapy for your page fetching and Beautiful Soup for the parsing. This would make your code a lot simpler.

    Whether you want to change your existing code that works to these alternatives is up to you. If not, then regular expressions would probably simplify your code somewhat. I’m not sure what effect it would have on performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 247k
  • Answers 247k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Firstly, if you want to test caching in the development… May 13, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer git ls-tree -r --name-only <commit> (where instead of <commit> there… May 13, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer There's a utility called StartUpManager, which should handle this problem.… May 13, 2026 at 8:45 am

Related Questions

First, let me state that this is a programming question (and thus does not
I want to write a following script: given a text file with the list
I keep typing t eh instead of the which is, of course, annoying in
I have been asked to fix a Community Server forum where thousands of users

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.