I'm writing a crawler with PHP that reads the HTML and stores it in a variable. The code works great if the site doesn't have a redirect. If I crawl the Google, for example, I have the following:
CURL Result
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.br/?gfe_rd=cr&ei=A14yVviJCuyp8wfmyIfIBg">here
</A>.
</BODY></HTML>
PHP method
private function parseHTML($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Apple-Tz: 0', 'X-Apple-Store-Front: 143444,12'));
ob_start();
curl_exec($curl);
curl_close($curl);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
How can I redirect to the destination page, crawl the HTML and return the code?