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 8394811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:09:00+00:00 2026-06-09T20:09:00+00:00

i wrote an easy url validator and shortener in python, how can i save

  • 0

i wrote an easy url validator and shortener in python, how can i save an image in small size from the website url? and recognise that it is not a “file” like .rar or .zip? i apreciate if you edit my code to have a better performance..

from urllib2 import Request, urlopen, URLError
from urlparse import urlparse
import string
import random

url = raw_input('plZ enter the url: ').lower()      #get input and convert to lowercase
while True:
    if url[0:7] == 'http://' or url[0:8] == 'https://' or url[0:6] =='ftp://':          #check the url protocol
        try:                                        #try to open url
            response = urlopen(url)
            parsed_url = urlparse(url)
            rand_url = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(6))
            print " The shortened url is: http://url.com/" + rand_url
            print "\n Original URL is: "+url
            exit()
        except URLError, e:                         #except the error by asking the address again
            if hasattr(e, 'reason'):
                print "URL is not valid or server is NOT responsive..plZ try again.."
                url = raw_input('plZ enter the url: ').lower()
            #print 'Reason: ', e.reason
            elif hasattr(e, 'code'):
                print 'The server couldn\'t fulfill the request.'       #message in case of server or connection error
                print 'Error code: ', e.code
    else:
        print "\n protocol missing, using HTTP instead.. \n"
        url = "http://"+url
  • 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. Editorial Team
    Editorial Team
    2026-06-09T20:09:01+00:00Added an answer on June 9, 2026 at 8:09 pm

    1) If you are looking to grab and image and resize it, Consider using either PIL or PyImageMagik [Python bindings for the excellent ImageMagik]

    2) If you are looking to grab the screenshot of the page, then many people have the asked the same before. You can always use the solutions mentioned in point 1) above after grabbing the screenshot to resize. Webkit2png is good tool to realize the same.

    http://www.paulhammond.org/webkit2png/

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

Sidebar

Related Questions

I couldn't find any good application for streaming MP3s from a URL that can
Is there an easy way to write C code that can access its Git
Python allows easy creation of an integer from a string of a given base
I am a JS novice so go easy on me here. But I wrote
I am looking to write something that seems like it should be easy enough,
Probably really easy for a pro, but could someone re-write this from it's PHP
I'm going to write a program that takes a URL and counts the occurrences
You would think with all the posts here that this would be easy to
I have a method to generate fully qualified URLs that I wrote which I
I would like to write Python script, which will get i.e. 100 news/texts from

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.