Hi there,
Does anyone know of a decent PHP function to scrape the HTML from a webpage because file_get_contents doesn't always work.
Trying this at the moment but it says "Bad Request":
Thanks.
Does anyone know of a decent PHP function to scrape the HTML from a webpage because file_get_contents doesn't always work.
Trying this at the moment but it says "Bad Request":
Code:
function GetPageHTML ($URL)
{
$userAgent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
$curl = curl_init($URL);
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_TIMEOUT, 2 );
$html = curl_exec( $curl );
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8');
curl_close( $curl );
return $html;
}
Thanks.