php采集程序,大概应该是这个思路

今天王哥让我手动添加视频到自己公司的网站上,因为采集功能坏掉了,所以只能手动添加了。我想是不是我应该做一个类似采集的程序呢?自己就会php,而且早就有用php做一个采集程序的想法,自己的想法就是用php的文件函数读去url上的内容,然后根据标签截取想要的内容,趁着王哥出去办事去了,我偷偷的写了下,

这段程序是首先读取一个目录的页面,然后把里面的视频链接添加到一个数组中,然后再遍历数组,读取里面的内容,然后在用字符串函数截取自己想要的那段内容,当然了,这段程序没有通用性,我只是根据一个视频网站的html源代码做的,也只能用在这个网站上。

顺便贴下这个网址:http://u.pomoho.com/lfw(这里面有很多分类栏目,社会,娱乐,游戏,其他等等,输入这些链接就能读取里面的视频的标题和视频,视频是由一个div包着的)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type = "text/css">
*{
margin:0;
padding:0;
}
body{
background-color:#dfdfdf;
text-align:center;
}
.con{
width:1000px;
height:120px;
}
.h{
width:400px;
}
.r{
width:500px;
height:50px;
margin:5px 0;

}
.b{
width:1000px;
margin:0 auto;
}
</style>
<script type = "text/javascript">

function copy(obj){

window.clipboardData.setData("Text",obj.value);
alert("Success!");
}
function check(){

$o = document.getElementById("url");
if($o.value){
document.getElementById("form1").submit();


}else{
alert("不能为空!");

}
}

</script>

</head>
<body>
<div class = "r">
<form method = "post" id = "form1" action = "./index.php" onsubmit = "return check();">
请输入网址:<input type = "text" name = "url" id = "url"/>&nbsp;<input type = "submit" value = "OK" />


</form>

</div>


<?php
if(isset($_POST['url'])){
echo "<div class = 'b'><table border = '1' width = '100%'>";
$url = $_POST['url'];

//存放视频url的数组
$arr_url = array();
$f = file_get_contents($url);
$str = strstr($f,"<div class=\"bmh_sp_pic\">");
$pos = 0;
$flag = true;
while($flag){




$pos = stripos($str,"<a href=\"http://u.baomihua.com/lfw/",$pos);
if($pos == false){
$flag = false;

}

$str = substr($str,$pos);
$end_pos = stripos($str,"target=_blank");
$s = substr($str,0,$end_pos -1);
$s = substr($s,8);
array_push($arr_url,$s);
//$d += substr($str,0,$end_pos-1);

$str = substr($str,$end_pos-1);
//echo $str;

}


$arr_url = array_unique($arr_url);

for( $m = 0; $m < count($arr_url);$m++){
$temp = $arr_url[$m];
$s = trim($temp,"\"");
$v = @file_get_contents($s);
//找标题
$p = stripos($v,"<h2 style=\"display:none\">");
$p2 = stripos($v,"</h2>",$p);
$t = substr($v,$p+25,$p2-$p);
$t = substr($t,0,strrpos($t,"</h2>"));
echo "<tr><td style = 'background-color:#8d8d8d;'><input type = \"text\" value = \"{$t}\" onclick = \"copy(this);\" class = 'h'/></td><td>{$s}</td></tr>";

$pos = stripos($v,"class=\"video\"");
$str2 =substr($v,$pos - 5);
$end_pos = stripos($str2,"</div>");
$str2 = substr($str2,0,$end_pos+6);
$sss = htmlspecialchars($str2);
echo "<tr><td colspan = '2'><textarea onclick = \"copy(this)\" class = 'con'>{$sss}</textarea></td></tr>";
}
echo "</table></div>";
}

?>


</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值