I'm trying to be a bit sneeky and as part of a learning process try and improve my page scraping skills.
One thing i've come across that I have yet to be able to solve is that certain sites will use an internal link which then redirects to an external link.
What I want to do is modify some curl code to follow the redirects until they stop and then obtain the final resting place URL.
Anyone recommend some code for me?
I have this at the moment, but it's not following the redirects properly at the moment.
$opts = array(CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true);
$curl = curl_init();
curl_setopt_array($curl, $opts);
$str = curl_exec($curl);
curl_close($curl);