编辑整理:整理来源:爱奇艺,浏览量:80,时间:2023-01-06 08:39:01
泛目录php推送,泛目录php推送,泛目录php推送
大家都知道网站需要时效性强的内容,那么泛目录更注重这点,内容时效性强且及时更新就是泛目录首先要解决的问题。今天,错误博客(cuowu.com)分享的内容为《PHP24小时自动更新采集标题》。希望对大家有所帮助。
一、自动采集原理
自动采集用的是三个php文件,每个文章均放一个header("refresh;url"),A里面放B,B里面放C,C里面放A,开始只需要运行A,那么B过一定时间就会运行一次,B运行时会运行C一次,C运行时会回到A,周而复始,这样子就可以让三个php文件24小时内自动采集了。
header("refresh:600;url=./cuowucom_biaotiA.php");header("refresh:6;url=./cuowucom_biaotiB.php");header("refresh:26;url=./cuowucom_biaoti.php");
如下图所示为采集到的标题:
二、PHP采集标题到txt
泛目录程序中需要调用一些时效性强的标题,采用PHP程序实现自动采集并存放到txt中,会很方便。至少比以前介绍的利用宝塔来定时访问要好很多,因为宝塔定时访问可能会增加不少问题出现概率。三个PHP采集中国新闻网的源码如下:
cuowu_biaoti.php
$txtnames ="cuowucom/biaoti/cuowucom-biaoti.txt";
header("refresh:6;url=./cuowucom_biaotiA.php");
set_time_limit(0);
$imgline="";
function preg_substr($start, $end, $str)
$temp = preg_split($start, $str);
$content = preg_split($end, $temp[1]);
return $content[0];
function str_substr($start, $end, $str)
$temp = explode($start, $str, 2);
$content = explode($end, $temp[1], 2);
return $content[0];
function microtime_float()
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
function getiurl($id)
global $imgline;
$str=$imgline[$id];
return $str;
$abcd=file_get_contents("http://www.chinanews.com/theory.shtml");
$hello = explode('',str_substr('
', '
', $abcd));
$abcd2=file_get_contents("http://www.chinanews.com/jiankang.shtml");
$hello2 = explode('',str_substr('
', '
', $abcd2));
$abcd3=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello3 = explode('',str_substr('
', '
', $abcd3));
$abcd4=file_get_contents("http://www.chinanews.com/society.shtml");
$hello4 = explode('',str_substr('
', '
', $abcd4));
$abcd5=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello5 = explode('',str_substr('
', '
', $abc5));
$abcd6=file_get_contents("http://www.chinanews.com/jiankang.shtml");
$hello6 = explode('',str_substr('
', '
', $abcd6));
$abcd7=file_get_contents("http://www.chinanews.com/theory.shtml");
$hello7 = explode('',str_substr('
', '
', $abcd7));
$abcd8=file_get_contents("http://www.chinanews.com/society.shtml");
$hello8 = explode('',str_substr('
', '
', $abcd8));
$abcd9=file_get_contents("http://www.chinanews.com/world.shtml");
$hello9 = explode('',str_substr('
', '
', $abcd9));
$abcd10=file_get_contents("http://www.chinanews.com/scroll-news/news1.html");
$hello10 = explode('',str_substr('
', '
', $abcd10));
$abcd11=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello11 = explode('',str_substr('
', '
', $abcd11));
$abcd12=file_get_contents("http://www.chinanews.com/scroll-news/news3.html");
$hello12 = explode('',str_substr('
', '
', $abcd12));
$abcd13=file_get_contents("http://www.chinanews.com/scroll-news/news4.html");
$hello13 = explode('
',str_substr('
', '
', $abcd13));
$myfile = fop($txtnames, "w") or die("错误博客 cuowu.com Unable to op file!");
for($index=0;$index
$hello[$index]=str_substr('shtml">', '', $hello[$index]);
echo $hello[$index]."
";
fwrite($myfile, $hello[$index]."
");
for($index=0;$index
$hello2[$index]=str_substr('shtml">', '', $hello2[$index]);
echo $hello2[$index]."
";
fwrite($myfile, $hello2[$index]."
");
for($index=0;$index
$hello3[$index]=str_substr('shtml">', '', $hello3[$index]);
echo $hello3[$index]."
";
fwrite($myfile, $hello3[$index]."
");
for($index=0;$index
$hello4[$index]=str_substr('shtml">', '', $hello4[$index]);
echo $hello4[$index]."
";
fwrite($myfile, $hello4[$index]."
");
for($index=0;$index
$hello5[$index]=str_substr('shtml">', '', $hello5[$index]);
echo $hello5[$index]."
";
fwrite($myfile, $hello5[$index]."
");
for($index=0;$index
$hello6[$index]=str_substr('shtml">', '', $hello6[$index]);
echo $hello6[$index]."
";
fwrite($myfile, $hello6[$index]."
");
for($index=0;$index
$hello7[$index]=str_substr('shtml">', '', $hello7[$index]);
echo $hello7[$index]."
";
fwrite($myfile, $hello7[$index]."
");
for($index=0;$index
$hello8[$index]=str_substr('shtml">', '', $hello8[$index]);
echo $hello8[$index]."
";
fwrite($myfile, $hello8[$index]."
");
for($index=0;$index
$hello9[$index]=str_substr('shtml">', '', $hello9[$index]);
echo $hello9[$index]."
";
fwrite($myfile, $hello9[$index]."
");
for($index=0;$index
$hello10[$index]=str_substr('shtml">', '', $hello10[$index]);
echo $hello10[$index]."
";
fwrite($myfile, $hello10[$index]."
");
for($index=0;$index
$hello11[$index]=str_substr('shtml">', '', $hello11[$index]);
echo $hello11[$index]."
";
fwrite($myfile, $hello11[$index]."
");
for($index=0;$index
$hello12[$index]=str_substr('shtml">', '', $hello12[$index]);
echo $hello12[$index]."
";
fwrite($myfile, $hello12[$index]."
");
for($index=0;$index
$hello13[$index]=str_substr('shtml">', '', $hello13[$index]);
echo $hello13[$index]."
";
fwrite($myfile, $hello13[$index]."
");
fclose($myfile);
cuowu_biaotiA.php
$txtnames ="cuowucom/biaoti/cuowucom-biaotiA.txt";
header("refresh:6;url=./cuowucom_biaotiB.php");
set_time_limit(0);
$imgline="";
function preg_substr($start, $end, $str)
$temp = preg_split($start, $str);
$content = preg_split($end, $temp[1]);
return $content[0];
function str_substr($start, $end, $str)
$temp = explode($start, $str, 2);
$content = explode($end, $temp[1], 2);
return $content[0];
function microtime_float()
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
function getiurl($id)
global $imgline;
$str=$imgline[$id];
return $str;
$abcd=file_get_contents("http://www.chinanews.com/society.shtml");
$hello = explode('',str_substr('
', '
', $abcd));
$abcd2=file_get_contents("http://www.chinanews.com/scroll-news/news5.html");
$hello2 = explode('',str_substr('
', '
', $abcd2));
$abcd3=file_get_contents("http://www.chinanews.com/scroll-news/news6.html");
$hello3 = explode('',str_substr('
', '
', $abcd3));
$abcd4=file_get_contents("http://www.chinanews.com/scroll-news/news7.html");
$hello4 = explode('',str_substr('
', '
', $abcd4));
$abcd5=file_get_contents("http://www.chinanews.com/scroll-news/news8.html");
$hello5 = explode('
',str_substr('
', '
', $abcd5));
$abcd6=file_get_contents("http://www.chinanews.com/mil/news.shtml");
$hello6 = explode('',str_substr('
', '
', $abcd6));
$abcd7=file_get_contents("http://www.chinanews.com/scroll-news/news5.html");
$hello7 = explode('',str_substr('
', '
', $abcd7));
$abcd8=file_get_contents("http://www.chinanews.com/scroll-news/news6.html");
$hello8 = explode('',str_substr('
', '
', $abcd8));
$abcd9=file_get_contents("http://www.chinanews.com/scroll-news/news7.html");
$hello9 = explode('',str_substr('
', '
', $abcd9));
$abcd10=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello10 = explode('
',str_substr('
', '
', $abcd10));
$myfile = fop($txtnames, "w") or die(" Unable to op file!");for($index=0;$index
$hello[$index]=str_substr('shtml">', '', $hello[$index]);
echo $hello[$index]."
";
fwrite($myfile, $hello[$index]."
");
for($index=0;$index
$hello2[$index]=str_substr('shtml">', '', $hello2[$index]);
echo $hello2[$index]."
";
fwrite($myfile, $hello2[$index]."
");
for($index=0;$index
$hello3[$index]=str_substr('shtml">', '', $hello3[$index]);
echo $hello3[$index]."
";
fwrite($myfile, $hello3[$index]."
");
for($index=0;$index
$hello4[$index]=str_substr('shtml">', '', $hello4[$index]);
echo $hello4[$index]."
";
fwrite($myfile, $hello4[$index]."
");
for($index=0;$index
$hello5[$index]=str_substr('shtml">', '', $hello5[$index]);
echo $hello5[$index]."
";
fwrite($myfile, $hello5[$index]."
");
for($index=0;$index
$hello6[$index]=str_substr('shtml">', '', $hello6[$index]);
echo $hello6[$index]."
";
fwrite($myfile, $hello6[$index]."
");
for($index=0;$index
$hello7[$index]=str_substr('shtml">', '', $hello7[$index]);
echo $hello7[$index]."
";
fwrite($myfile, $hello7[$index]."
");
for($index=0;$index
$hello8[$index]=str_substr('shtml">', '', $hello8[$index]);
echo $hello8[$index]."
";
fwrite($myfile, $hello8[$index]."
");
for($index=0;$index
$hello9[$index]=str_substr('shtml">', '', $hello9[$index]);
echo $hello9[$index]."
";
fwrite($myfile, $hello9[$index]."
");
for($index=0;$index
$hello10[$index]=str_substr('shtml">', '', $hello10[$index]);
echo $hello10[$index]."
";
fwrite($myfile, $hello10[$index]."
");
fclose($myfile);
cuowu_biaotiB.php
$txtnames ="cuowucom/biaoti/cuowucom-biaotiB.txt";
header("refresh:26;url=./cuowucom_biaoti.php");
set_time_limit(0);
$imgline="";
function preg_substr($start, $end, $str)
$temp = preg_split($start, $str);
$content = preg_split($end, $temp[1]);
return $content[0];
function str_substr($start, $end, $str)
$temp = explode($start, $str, 2);
$content = explode($end, $temp[1], 2);
return $content[0];
function microtime_float()
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
function getiurl($id)
global $imgline;
$str=$imgline[$id];
return $str;
$abcd=file_get_contents("http://www.chinanews.com/compatriot.shtml");
$hello = explode('',str_substr('
', '
', $abcd));
$abcd2=file_get_contents("http://www.chinanews.com/business/gd.shtml");
$hello2 = explode('',str_substr('
', '
', $abcd2));
$abcd3=file_get_contents("http://www.chinanews.com/taiwan.shtml");
$hello3 = explode('',str_substr('
', '
', $abcd3));
$abcd4=file_get_contents("http://www.chinanews.com/scroll-news/news1.html");
$hello4 = explode('',str_substr('
', '
', $abcd4));
$abcd5=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello5 = explode('
',str_substr('
', '
', $abcd5));
$abcd6=file_get_contents("http://www.chinanews.com/entertainment.shtml");
$hello6 = explode('',str_substr('
', '
', $abcd6));
$abcd7=file_get_contents("http://www.chinanews.com/ty/gun-news.html");
$hello7 = explode('',str_substr('
', '
', $abcd7));
$abcd8=file_get_contents("http://www.chinanews.com/wenhua.shtml");
$hello8 = explode('',str_substr('
', '
', $abcd8));
$abcd9=file_get_contents("http://www.chinanews.com/scroll-news/news1.html");
$hello9 = explode('',str_substr('
', '
', $abcd9));
$abcd10=file_get_contents("http://www.chinanews.com/scroll-news/news2.html");
$hello10 = explode('',str_substr('
', '
', $abcd10));
$myfile = fop($txtnames, "w") or die("错误博客Unable to op file!");
for($index=0;$index
$hello[$index]=str_substr('shtml">', '', $hello[$index]);
echo $hello[$index]."
";
fwrite($myfile, $hello[$index]."
");
for($index=0;$index
$hello2[$index]=str_substr('shtml">', '', $hello2[$index]);
echo $hello2[$index]."
";
fwrite($myfile, $hello2[$index]."
");
for($index=0;$index
$hello3[$index]=str_substr('shtml">', '', $hello3[$index]);
echo $hello3[$index]."
";
fwrite($myfile, $hello3[$index]."
");
for($index=0;$index
$hello4[$index]=str_substr('shtml">', '', $hello4[$index]);
echo $hello4[$index]."
";
fwrite($myfile, $hello4[$index]."
");
for($index=0;$index
$hello5[$index]=str_substr('shtml">', '', $hello5[$index]);
echo $hello5[$index]."
";
fwrite($myfile, $hello5[$index]."
");
for($index=0;$index
$hello6[$index]=str_substr('shtml">', '', $hello6[$index]);
echo $hello6[$index]."
";
fwrite($myfile, $hello6[$index]."
");
for($index=0;$index
$hello7[$index]=str_substr('shtml">', '', $hello7[$index]);
echo $hello7[$index]."
";
fwrite($myfile, $hello7[$index]."
");
for($index=0;$index
$hello8[$index]=str_substr('shtml">', '', $hello8[$index]);
echo $hello8[$index]."
";
fwrite($myfile, $hello8[$index]."
");
for($index=0;$index
$hello9[$index]=str_substr('shtml">', '', $hello9[$index]);
echo $hello9[$index]."
";
fwrite($myfile, $hello9[$index]."
");
for($index=0;$index
$hello10[$index]=str_substr('shtml">', '', $hello10[$index]);
echo $hello10[$index]."
";
fwrite($myfile, $hello10[$index]."
");
fclose($myfile);
以上就是错误博客(cuowu.com)分享的内容为《PHP24小时自动更新采集标题》。感谢您的阅读。更多原创文章搜索“错误博客”。
扩展资料:php还可以读取文件夹下所有图片,方法如下
hostdir=dirname(__FILE__).'/data/upload/admin/20170517/'; //要读取的文件夹
(此处空一行)
$url = '/data/upload/admin/20170517/'; //图片所存在的目录
(此处空一行)
$filesnames = scandir($hostdir); //得到所有的文件
(此处空一行)
// print_r($filesnames);exit;
//获取也就是扫描文件夹内的文件及文件夹名存入数组 $filesnames
(此处空一行)
$www = 'http://www.***.com/'; //域名
(此处空活吧欢抓底盐力九机指一行)
foreach ($filesnames as $name) {
$aurl= ""; //图片
echo $aurl . "
"; //输出他