473,382 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Downloading images?

YarrOfDoom
1,247 Expert 1GB
I'm trying to create a script to download a series of images for me, problem is that I have no idea on how to actually get them from the internet to my computer. I've been thinking this:
Expand|Select|Wrap|Line Numbers
  1. import urllib2
  2. request = urllib2.Request(imageurl)
  3. try: response = urllib2.urlopen(request)
  4. except URLError, err:
    # code responsible for going on with the next series
    c_image = response.read()
Would this work and how could I get c_image as a file on my computer?
Oct 16 '08 #1
1 1266
YarrOfDoom
1,247 Expert 1GB
After scrambling together information about this from all over the internet (but mostly the python docs) I found out how to do it.
Expand|Select|Wrap|Line Numbers
  1. import urllib2
  2. request = urllib2.Request(image url)
  3. try: response = urllib2.urlopen(request)
  4. except URLError, err:
  5.     pass #here will come code that is irrelevant to my problem
  6. c_image = response.read()
  7. file = open(desired filename and location, "wb")
  8. file.write(c_image)
  9. file.close()
Still thanks to anyone who was trying to help, but wasn't fast enough.
For anyone trying to learn something from this: I'm using writing mode "wb" to write the file in binary mode, as images aren't ASCII files, and can't be written in the normal writing mode.
Oct 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Marc | last post by:
Hello, I have a page with lots of thumbnails of photos. I want the user to be able to dload a big version of the photo (also present on the server) by either 1) clicking on it (left...
2
by: Dave | last post by:
Dear Sirs, Is there a way to get the width and height of an image without downloading the image, or with just downloading a minimal portion of the image? For instance, I have a list of 10,000...
23
by: Doug van Vianen | last post by:
Hi, Is there some way in JavaScript to stop the downloading of pictures from a web page? Thank you. Doug van Vianen
4
by: aldonnelley | last post by:
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files...
3
by: JP SIngh | last post by:
Can someone please help me with a file download query. I have the following code which works fine. The only change I want to make is in the line objStream.loadfromfile...
3
by: xeroxero | last post by:
I would like to prevent people from downloading a .zip from a ASP.NET 2.0 web site, but still allow people to touch a .aspx page in the same directory. I also want to set things so if a user clicks...
1
by: Hans Olav Hygen | last post by:
On 23. of October last year a the follwing was posted to this group: There were two advices (use urllib2 and "wb"). I tried to build this script on this basis: import win32api import...
5
by: OBAFGKM_RNS | last post by:
I have a javascript timer on my page that counts to 10. Every half second it alternates images on my buttons from a lighter image to a darker image, giving the appearance of the buttons blinking....
4
by: surja | last post by:
Hi, I have written a code to download images from a server end desktop, but while running the code ,WTK is showing a runtime error " Create image from Byte array Uncaught exception...
6
by: dysfunct | last post by:
Question: If I have a lot of <imgtags on a site, all linking from all sorts of domains, is there a way to check to see which ones have finished downloading and which ones haven't? For example let's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.