473,406 Members | 2,220 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,406 software developers and data experts.

Saving a picture contained in a web page to disk

Hi there,

I would like to save to disk a picture contained in a webpage.

Unfortunately the image is dynamic, so the url is actually a query
which looks like

http://adfarm.mediaplex.com/ad/bn/23...68644406357385

rather than the standard

http://img-cdn.mediaplex.com/ads/239...on_120x600.gif

I've been told that a scripting language like Perl, Python or PHP is
my best bet for this kind of tasks, would you agree?
Could you please give a few function names to look at as a starting
point?
That should suffice, although a code snippet would be greatly
appreciated.
;)

Thank you very much in advance for your help.

Regards,
Giulio

Jul 18 '05 #1
7 4669
Giulio Cespuglio:
I would like to save to disk a picture contained in a webpage.

Unfortunately the image is dynamic, so the url is actually a query
which looks like

http://adfarm.mediaplex.com/ad/bn/23...68644406357385

rather than the standard

http://img-cdn.mediaplex.com/ads/239...on_120x600.gif
That doesn't matter at all.
I've been told that a scripting language like Perl, Python or PHP is
my best bet for this kind of tasks, would you agree?
Absolutely! :-)
Could you please give a few function names to look at as a starting
point?
That should suffice, although a code snippet would be greatly
appreciated.


Try running this code and see what you think:

#########################

import urllib

def saveUrlToFile( url, fileName ):
f = open( fileName, 'wb' )
data = urllib.urlopen(url).read()
f.write( data )
f.close()

saveUrlToFile(

'http://adfarm.mediaplex.com/ad/bn/2397-11787-1843-5?mpt=1068644406357385',
'test.gif' )

#########################

-Mike
Jul 18 '05 #2
Giulio Cespuglio wrote:
I would like to save to disk a picture contained in a webpage.

Unfortunately the image is dynamic, so the url is actually a query
which looks like

http://adfarm.mediaplex.com/ad/bn/23...68644406357385

rather than the standard

http://img-cdn.mediaplex.com/ads/239...on_120x600.gif


Unless you have more requirements that you did not mention, I fail
to see why this is a problem, and why you have to write a program
to do this.

Right click the image, 'save image as'.

Or use a tool such as wget or curl to directly download
the URL above, even the 'dynamic one'.

--Irmen

Jul 18 '05 #3
> saveUrlToFile(

'http://adfarm.mediaplex.com/ad/bn/2397-11787-1843-5?mpt=1068644406357385', 'test.gif' )


That got formatted oddly for some reason, although it should still work.

-Mike
Jul 18 '05 #4
>>>>> "Michael" == Michael Geary <Mi**@DeleteThis.Geary.com> writes:

Michael> Try running this code and see what you think:

You mean

import urllib
urllib.urlretrieve(url, filename)

right?

<wink>,
JDH

Jul 18 '05 #5
John Hunter wrote:

You mean

import urllib
urllib.urlretrieve(url, filename)

right?

<wink>,
JDH


Oh! Thank you--that's much better than the code I posted. :-)

-Mike
Jul 18 '05 #6
Irmen de Jong <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> wrote in message news:<3f***********************@news.xs4all.nl>...
Giulio Cespuglio wrote:
I would like to save to disk a picture contained in a webpage.

Unfortunately the image is dynamic, so the url is actually a query
which looks like

http://adfarm.mediaplex.com/ad/bn/23...68644406357385

rather than the standard

http://img-cdn.mediaplex.com/ads/239...on_120x600.gif


Unless you have more requirements that you did not mention, I fail
to see why this is a problem, and why you have to write a program
to do this.

Right click the image, 'save image as'.

Or use a tool such as wget or curl to directly download
the URL above, even the 'dynamic one'.

--Irmen

you did miss it, he needs to do it with Python as do I anyone have a
helpful piece of code that works as an example?
Jul 18 '05 #7
>>>>> "Y2KYZFR1" == Y2KYZFR1 <ja*************@yahoo.com> writes:
> Unfortunately the image is dynamic, so the url is actually a

query > which looks like http://adfarm.mediaplex.com/ad/bn/23...68644406357385
>
> rather than the standard
>
>

http://img-cdn.mediaplex.com/ads/239...on_120x600.gif


If the query is dynamic, you may need to sniff the HTTP headers to
find out what is going on behind the scenes. Mozilla Firebird has a
'Live HTTP Headers' addon module that lets you captue and save the
headers as you browse. You can then sort through them, find out what
is going on, and use the httplib module to code it in python.

Not easy, but doable.

JDH

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: S. Stilwell | last post by:
I'm trying to write a small program that will go to a particular web site and download an image file on a schedule. I just need to know how to save the file to disk from a website. Any help would...
4
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle...
1
by: MC | last post by:
How can we save entire html web pages to io streams, including picture files (jpeg, gif, etc.) and other linked files if any. We need to be able to save to disk entire html pages, not just their...
1
by: Espen Evje | last post by:
Hi, I am trying to present the images in a folder as thumbnails in a dynamically created asp:table. I however do not want to save the thumbnails to disk, only show the images in this folder as...
1
by: Laszlo Csabi | last post by:
Hi guys, Anyone knows about how to save a picture from a html page to the hard disk either in C# or VB.NET? What I have done so far is the following and it doesn't work. I got an empty image...
4
by: Dixon | last post by:
Hai Im a newbie I have a picture in a picture box I drag a portion of the picture with the mouse..... Here i get the area i dragged in and now i want that area to be a separate picture...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.