时间:2021-07-01 10:21:17 帮助过:20人阅读
$url = "http://news.qq.com/newsgn/zhxw/shizhengxinwen.htm";
$urlcontent = file_get_contents($url);
preg_match_all("//isU", $urlcontent, $urlcontent);
//程序运行到此正常,能拿出列表页要采集新闻的连接
$urllength=count($urlcontent[1]);
$conpattern = "/.+(.+)<\/h1>.+(.+)<\/span>.+(.+)/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]."
";
}
}