一个新闻采集功能,朋友们指教!
批量采集的时候有时候会有一些新闻不能采集到(只是少部分),不清楚什么原因,朋友们帮看下
我是采集腾讯的新闻
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
$url = "http://news.qq.com/newsgn/zhxw/shizhengxinwen.htm";
$urlcontent = file_get_contents($url);
preg_match_all("/<a.{1,20}href=\"(http:\/\/news\.qq\.com\/.{1,50}\/\d{1,20}\.htm)\".{1,80}<span class=\"pub\_time\">/isU", $urlcontent, $urlcontent);
//程序运行到此正常,能拿出列表页要采集新闻的连接
$urllength=count($urlcontent[1]);
$conpattern = "/<div id=\"C-Main-Article-QQ\" class=\"mod-left\">.+<h1>(.+)<\/h1>.+<span class=\"pubTime\">(.+)<\/span>.+<div id=\"Cnt-Main-Article-QQ\" bossZone=\"content\">(.+)<div class=\"ft\">/isU";
for($i=0;$i<=$urllength-1;$i++){
$newstr = file_get_contents($urlcontent[1][$i]);
preg_match_all($conpattern, $newstr, $art_arr);
if(isset($art_arr[1][0])){ //因为有时候采集不到,所以我在这里判断下,问题就在这里,不知道什么原因采集不到,朋友们帮分析下。谢谢了
echo $art_arr[1][0]."<br />";
}
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号