Re: Saving a picture contained in a web page to disk

From: Michael Geary (Mike_at_DeleteThis.Geary.com)
Date: 11/13/03


Date: Wed, 12 Nov 2003 15:09:50 -0800

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/2397-11787-1843-5?mpt=1068644406357385
>
> rather than the standard
>
> http://img-cdn.mediaplex.com/ads/2397/11787/q2_dell_inspiron_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



Relevant Pages

  • Saving a picture contained in a web page to disk
    ... I would like to save to disk a picture contained in a webpage. ... so the url is actually a query ... although a code snippet would be greatly ...
    (comp.lang.python)
  • Re: Hyperlinks
    ... folder on the same root level as my index.htm & index_file. ... labeled each picture only to realize that on mouseover it just said "picture" ... Now use this code snippet: ... the link points to a webpage and the IMG points to an image ...
    (microsoft.public.publisher.webdesign)
  • Re: Hyperlinks
    ... For some reason Microsoft decided to disable the right click, save picture ... Your easiest workaround is to upload the ... the code snippet to import your images into your page, ... Again, the link is pointing to the same webpage, ...
    (microsoft.public.publisher.webdesign)
  • Re: Hyperlinks
    ... Now use this code snippet: ... the link points to a webpage and the IMG points to an image ... the image to be shown on the webpage is sourced from a file on my website. ... I'm still working on layout (e.g. picture size, links, navigation, ...
    (microsoft.public.publisher.webdesign)
  • Re: Saving BMP file to disk in CF
    ... try this code snippet instead...fortunately I don't work for ... just a meer grunt;P ... > I am trying to use Alex Feinman's code to save a bitmap to disk that was ...
    (microsoft.public.dotnet.framework.compactframework)