file_get_contents() 在具体网站上不起作用

use*_*746 0 html php curl

我正在尝试从网站 www.pornhub.com 获取 HTML 内容(不要问为什么:D)但经典

file_get_contents('http://www.pornhub.com');
Run Code Online (Sandbox Code Playgroud)

不起作用。我也试过

$Url = 'https://www.pornhub.com/categories';

if (!function_exists('curl_init')){ 
    die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
Run Code Online (Sandbox Code Playgroud)

但它也不起作用。

有谁知道我做错了什么?

感谢您的帮助。

Kev*_*vin 5

请试试这个:

$Url = 'https://www.pornhub.com/categories';

if (!function_exists('curl_init')){
    die('CURL is not installed!');
}
$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // add this one, it seems to spawn redirect 301 header
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); // spoof
$output = curl_exec($ch);
curl_close($ch);

echo $output; // use echo to show contents
Run Code Online (Sandbox Code Playgroud)