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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.