感觉网站太空洞了,就找了找平时自己浏览的IT资讯网站,将内容抓取过来,这样就不能每个网站都浏览了.
//标题+预览 public function to_oschina(){ $datas=$this->_comm_oschina(); $this->mylib->My_show_list(mymsg::PZ_OSCHINA, 'pc/oschina',$datas,null,'no desc',5,$this->pagesize); } //仅标题 public function to_oschina_title(){ $datas=$this->_comm_oschina(); $this->mylib->My_show_list(mymsg::PZ_OSCHINA, 'pc/oschina_title',$datas,null,'no desc',5,$this->pagemax); } //在页面停留指定秒后开始抓取数据 function _comm_oschina(){ $datas=$this->mytool->getInfo(); $datas["url"]="http://www.oschina.net"; $datas["ajaxMethod"]="get_oschina"; $datas["funMethod"]="to_oschina"; return $datas; } //前台用ajax进行调用 function get_oschina(){ $this->_insert_oschina(); } function _insert_oschina(){ $url="http://www.oschina.net/news/list"; $html = file_get_html($url); $result = $html->find('.ArticleList ul li'); for($j=0;$jfind("td"); for($i=0;$ifind("h3 a",$i); if(!empty($h)){ $data["title"]=$h->innertext; //标题 $url=$h->href; $data["uri"]= str_replace("http://www.oschina.net","",$url);; //URI地址 } $p=$detail[$i]->find(".date",$i); if(!empty($p)){ $data["author_url"]=$p->find('a',$i)->href; //作者地址 $data["author_nm"]=$p->find('a',$i)->innertext; //作者名称 $data["time_detail"]=$p->innertext(); //作者发布信息 $data["no"]= substr($data["time_detail"],strrpos($data["time_detail"],"(")+1,16); } $d=$detail[$i]->find(".detail",$i); if(!empty($p)){ $data["info"]=$d->innertext; //简介 } } $bool=$this->mcom_model->checkIsExit(mymsg::PZ_OSCHINA,array("title"=>$data["title"])); if(!$bool){ $this->mcom_model->insert_data(mymsg::PZ_OSCHINA,$data); } } } 这样就能抓取oschina的资讯保存进数据库,刷新后可查看
查看实例:http://www.xiuxiandou.com/xitong/pachong/to_oschina