cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: how to click a link and download an image

From: Lars Nilsson <chamaeleon_at_gmail.com>
Date: Wed, 24 Aug 2005 14:30:13 -0400

On 8/24/05, leegold <leegold_at_fastmail.fm> wrote:
> Tried posting in the PHP list but no answer - please forgive my cross
> posting.
> Would appreciate a link or brief explaination for example showing the
> idea to do the following:
>
> Wondered if I could get a simple newbie example for the code to do the
> following, I'll be using PHP:
>
> I want to go to a website, and then, on that site click a link. The
> link will take me to a new page which shows a jpeg graphic. I then want
> to to download (via http protocol) this jpeg to a folder on my local
> hard drive.
>
> If you give me a general case of the code I'll put in the specifics.
> There's much more, but this would be a start.
>
> Lee G.

1. Get first page
2. Parse HTML for first page and extract url for second page
3. Get second page based on extracted url
4. Parse HTML for second page and extract url for jpeg
5. Get jpeg

Now you can just fill in the specifics. ;) libcurl only provides you
with the tools to do step 1, 3 and 5. It is your responsibility to do
the things that do not involve the transfer of data from the server to
your program (which includes figuring out what to do with the HTML
code and extract any relevant information, etc). The assumption for
the steps is of course that it is required to retrieve the two pages
before attempting the jpeg url (due to athentication, cookies, or lack
of a priori knowledge of the jpeg url, or for any other reason that
you have not mentioned).

Lars Nilsson
Received on 2005-08-24