我正在写一个新的代码,并试图从pornhub视频页面获取视频源网址使用curl与接口。
这段代码几天前运行的还不错,但是我想pornhub在他们的流媒体服务器上做了一些改动,它已经停止工作了。我的代码仍然在我的电脑的本地主机上运行,但是当我在服务器上运行时,我得到了403错误
function get_site_html_string($url, $cookie=NULL, $referer = NULL, $timeout = CURL_TIMEOUT){
$ip = 'x.x.x.x'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_INTERFACE,$ip);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6000);
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_NOPROGRESS, CURL_PROGRESS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.101 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($referer) {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ( $cookie ) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
$string = curl_exec($ch);
if (curl_errno($ch)) {
echo var_dump(curl_error($ch));
return FALSE;
}
curl_close($ch);
return $string;
}
function get_video_url_pornhub($url=''){
$html = get_site_html_string($url);
preg_match_all('/quality":"(.*?)","videoUrl":"(.*?)"/', $html, $matches_url);
foreach ($matches_url[2] as $k => $v) {
if (trim($v) != '') {
$videos[$matches_url[1][$k]] = stripslashes($v);
}
}
ksort($videos);
return $videos;
}
$url = 'https://www.pornhub.org/view_video.php?viewkey=ph5d27619512bda';
$videos = get_video_url_pornhub($url);
print_r($videos);
<video width="320" height="240" controls>
<source src="<?php echo $videos[480] ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
我的代码是成功地返回视频源网址,它是完美的工作,当我尝试我的电脑没有任何接口,但当我运行此代码在服务器上,在视频播放器或尝试访问(如wget使用相同的接口或 curl 的网址)我得到错误403。(对不起,我的英语)。
1条答案
按热度按时间ia2d9nvy1#
你找到解决办法了吗?我认为云耀斑阻止了它。