标签:des style blog http io color ar os 使用
大家都知道看免费电影少不了给你来点广告,引用别的网站视频到自己网站是可以,但广告不能少,怎样去广告,向下看吧!
一般获得播放器地址就是通过这样:
也可以点右键看源码,正则找到其地址。
也就是
1:file_get_contents/curl -->页面的html
2:正则分析视频地址
缺点:
1:慢,html页面比较大,有大量的信息是"杂质"信息
2:如果页面改版了,采集规则可能失效.
所以,我们不使用那种方法,使用下面这种
利用土豆的API,得到XML信息
1:XML是纯数据,内容少,获取快
2:纯数据,比如标题,时长等,这些是不会变的. 很难失效.
目前,各大网站都有自己的开放接口, application programing interface,应用程序接口
利用网站的API,就可查询信息
如豆瓣的书籍信息,土豆的视频信息.....
怎样获得API接口:
百度查找土豆api,注册应用程序,获得两个重要值
再根据api文档获得视频怎样使用
<?php
/***
$key = 1f3918053ff6bc04
***/
error_reporting(E_ALL & ~E_NOTICE);
if($tudou = $_POST['tudou']) {
$itemcode = basename($tudou);
$key = '1f3918053ff6bc04';
$api = 'http://api.tudou.com/v3/gw?method=item.info.get&appKey=' . $key . '&format=xml' . '&itemCodes=' . $itemcode;
// echo $api;
/*
echo $api,得到的是一个XML文档,内容是视频的标题,时长,封面等等信息
接下来我们要做的是用PHP把XML的各节点信息解析出来
知识点: DOMDocument类来解析
当前,我们暂时不用XML解析 ,而是直接用字符串操作来得到地址
*/
$source = file_get_contents($api);
$start = strpos($source,'<html5Url>');
$end = strpos($source,'</html5Url>');
$noad = substr($source,$start,$end-$start);
//echo $noad;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<pre> <!--/Dc6P2egJA4w 就是itemCodes-->
第28集http://www.tudou.com/programs/view/Dc6P2egJA4w/
</pre>
<h1>这个地址需要支持html5的浏览器才能看,如chrome,火狐,IE9以上</h1>
<form method="post">
<p>
土豆地址:<input type="text" name="tudou" />
</p>
<p>
<input type="submit" value="获取地址" />
</p>
</form>
<p>
无广告地址:<?php echo $noad; ?>
</p>
</body>
</html>
参考IT自学网。
标签:des style blog http io color ar os 使用
原文地址:http://blog.csdn.net/buyingfei8888/article/details/41243841