cURL和file_get_contents不适用于IMDb视频播放器链接

时间:2019-04-15 19:45:26

标签: php web-scraping

我试图从IMDb视频链接中删除预告片源。

我尝试使用file_get_contents();但我最终以[HTTP请求失败! HTTP / 1.1 400 Bad Request]错误,并且cURL给我302,发现文档已移到此处而不是页面源。

我正在尝试从给定的URL获取完整的源代码
例如

function url_get_contents($url) 
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
$url = "https://www.imdb.com/videoplayer/vi639154713?playlistId=tt6418918&ref_=tt_ov_vi";
$source = file_get_contents(urlencode($url));
//ends up with[ HTTP request failed! HTTP/1.1 400 Bad Request] or
//failed to open stream: No such file or directory in case of using urlencode
$source = url_get_contents($url);
//ends up with 302 Document has moved here .. probably missing the right options for curl
//--------//
//some scraping done with strpos and substr targeting the only video tag in the page "not the main problem"
echo $videoSourceLink;

//expected output for the previous url in the next comment---->
//https://imdb-video.media-imdb.com/vi639154713/1434659607842-pgv4ql-1547571245800.mp4?Expires=1555441981&Signature=gCtvwysi4WEvNbDuxBUCU75ABkTAprFhyt-P16D8o92fXFe~tWsYinU66VSMQT2f157d9f5dwkT3-vJcgT8aiJowsABIpkBd~oZIzJenM2e3W4wovZ8Z3l7NEmcGXjqhLpJ7eP2yu8JYZpgpSWeCIe7V5RiMhwIIPcKzlB3x6iWxy8rMRpaJZ8Vr7ZyadsIExbmCRK5OTFV4hZ2MbTMEtd-tRPKxthpzqaSQ18gvaBVH900SO76lqNWXRD-DnnSHjYsAnOVePfEqdff5o3PiaUpuGLEQbkNKlsgSPfYNHI74k6eOEGUehUjuzNCggb8LqActG7gPceOf4fD3xz4Vqg__&Key-Pair-Id=APKAIFLZBVQZ24NQH3KA

更新1:

现在当我使用正在使用cURL的url_get_contents函数时,它将给出此响应 enter image description here

0 个答案:

没有答案