Jump to content

CURL question follow url and pull next url from url bar


Trevors

Recommended Posts

Hi all,
Im curious if CURL can follow a link like this "http://www.blogcatalog.com/out/slike-iz-zivota-jednog-idiota.html" then when it redirects it pulls the real url and saves it.
I was gonna crawl whole http://www.blogcatalog.com/ but they got redirect urls which i dont want.
Would really appreciate abit of help

Best Regards
Trevor
I think I slightly misinterpreted your post even though the code snippet I linked you to does also have the answer. I thought you just wanted to get the address of the final url, but I realize now that you want the content (I think).

You may have figured it out but know that the only curl option you need to set is CURLOPT_FOLLOWLOCATION for curl to follow the redirects.
[code]
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
[/code]
[code]
<?php
$ch = curl_init();
$url = 'http://example.com/website/hello/329472';

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$r = curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch)

//$r has the content
//$url has the address
[/code]
Note the removal of the NOBODY option.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.