php 扒取网页数据
生活随笔
收集整理的這篇文章主要介紹了
php 扒取网页数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
扒取方法
public function index(){$url = 'http://www.dytt8.net/';// $url = 'Public/txt/movies.txt';$content = file_get_contents($url);$content = iconv("gb2312", "utf-8//IGNORE",$content);$reg = "|<div class=\"co_content2\">(.*?)<\/div>|is";//正則匹配div$res = preg_match_all($reg, $content, $match);$count = count($match[1]);//有數據if($count){$arr = array();$array = array();for($i=0;$i<$count;$i++){$a = "|<a[^>]*>(.*?)<\/a>|is"; //匹配value$patten="/<a href=[\'\"]?([^\'\" ]+).*?>/";//匹配href值preg_match_all($a, $match[1][$i], $mat);preg_match_all($patten, $match[1][$i], $href);foreach($mat[1] as $key=>$val){$array = array('href'=>'http://www.dytt8.net/'.$href[1][$key],'name'=>$val,'ctime'=>time(),);array_push($arr,$array);}}$res = $this->Movies->addAll($arr);if($res){echo '抓取成功!';}else{echo '抓取失敗!';}}} 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php 扒取网页数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到去地里掰玉米是什么意思
- 下一篇: [算法]-排序算法之希尔排序