views:

156

answers:

4

The following link outputs a different image every time you visit it:

http://www.biglickmedia.com/art/random/index.php

From a web browser, you can obviously right click it and save what you see. But if I were to visit this link from a command line (like through python+mechanize), how would I save the image that would output? So basically, I need a command-line method to imitate right clicking and saving the image after initially visiting the site from a web browser.

I can already use iMacro to do this, but I'd like a more elegant method. What can I use to accomplish this? Thanks!

+4  A: 

you might need something that creates a socket to the server and then issues a http GET request for "art/random/index.php". save the payload from the HTTP response, and then you have your data

what you would be creating is a simple HTTP client

the unix command wget does this:

$ wget http://www.biglickmedia.com/art/random/index.php
That should probably be just wget, not $wget
Josh
yeah, it was there to identify a command on the command line. improved formatting
+1  A: 
<?php
    file_put_contents('C:\\random.gif', file_get_contents('http://www.biglickmedia.com/art/random/index.php'));
?>
ken
+1  A: 

With Python and mechanize:

import mechanize

b = mechanize.Browser()
t = b.open(url)
image_type = t.info().typeheader # mime-type of image
data = t.read() #bytes of image
open(filename, 'wb').write(data)
Vinay Sajip
A: 

how do you grab the image in index.php with imacro?

If you have a follow up question you should post it asa new question, not as an answer to this old question.The "Ask Question" button is in the top right.
sth