php如何采集文章

有没有人在啊,想请教下,php如何采集文章
最新回答
满栀

2024-04-30 11:22:03

用网页抓取函数curl或者fopen或者file_get_contents,然后再用正则匹配来提取网页中的内容:
preg_match,preg_match_all基本就这两个步骤足够了!
追问
能不能详细点举个例子
追答
下边是获取msn佳缘网站会员信息的代码:
//Snoopy.class.php可以在网上下载:
set_time_limit(0);
require('../snoopy/Snoopy.class.php');
$snoopy = new Snoopy();
$path='usericon';
for($i=1;$ifetch($url);
$content=$snoopy->results;
//$content=iconv("GB2312","UTF-8",$content);
$content=trim($content);
preg_match_all("/
$temp_link[1][$j],"image_link"=>$img_link[1][$j],"image"=>$imgname);
//$id=$dbc->getOne("select id from spider_msn where link='".$temp_link[1][$j]."'");
if(empty($id))
{
// $dbc->AutoExecute("spider_msn",$array,"INSERT");
echo $temp_link[1][$j]."|".$img_link[1][$j]."|".$imgname."";
}
}
一群在校园浪费青春的疯子

2024-04-30 02:42:23

利用正则表达式来匹配获得的其他网站的内容,抠出来