ホームページ  >  記事  >  バックエンド開発  >  スヌーピーをベースにした PHP が Web サイトのコーディングをほぼ完璧に取得

スヌーピーをベースにした PHP が Web サイトのコーディングをほぼ完璧に取得

WBOY
WBOYオリジナル
2016-07-25 09:08:53878ブラウズ
スヌーピーをベースにした PHP が Web サイトのコーディングをほぼ完璧に取得
phpクローラーで使用していますが、コーディング精度は99.9%です。まだ取得できない部分があります。改善にご協力ください。
コードソース: Zhanyun.com www.siteyun.com
まず、Snoopy.class.php をオンラインでダウンロードする必要があります
メソッドの呼び出し: echo $go->getCharset(); ?>

[コード]url=$url; } //打开网站 プライベート関数オープン($url) { if($this->リクエスト!==null) { if($this->リクエスト->ステータス==200) { true を返します。 } それ以外 { false を返します。 } } それ以外 { $this->request=新しいスヌーピー(); $this->request->fetch($url); if($this->リクエスト->ステータス==200) { $this->request->results=strto lower($this->request->results); $charset=$this->getCharset(); if($charset!="utf-8") { if($charset=="windows-1252") { $this->request->results=$this->uni_decode($this->request->results); } それ以外 { $this->request->results=mb_convert_encoding($this->request->results,"UTF-8",$charset); } } true を返します。 } それ以外 { false を返します。 } } } //获取网站タイトル、キーワード、説明 パブリック関数 getWebinfo() { $info=配列( 'タイトル'=>'', 'キーワード'=>'', 'desc'=>'', 'ip'=>'' ); if(!$this->open($this->url)){return $info;exit;} // print_r($this->request->results);終了; preg_match('/([^>]*)/si', $this->request->results, $titlematch ); if (isset($titlematch) && is_array($titlematch) && count($titlematch) > 0) { $info['title'] = ストリップ_タグ($titlematch[1]); } preg_match_all('/"]*)"?[s]*' 。 'content="?([^>"]*)"?[s]*[/]?[s]*>/si', $this->request->results, $match); $フィート=0; foreach($match[1] as $mt) { if($mt=="キーワード" || $mt=="説明") { $フィート=1; } } if($ft==0) { preg_match_all('/"]*)"?[s]*name="?' . '([^>"]*)"?[s]*[/]?[s]*/si', $this->request->results, $match); if (isset($match) && is_array($match) && count($match) == 3) { $originals = $match[0]; $names = $match[2]; $values = $match[1]; if (count($originals) == count($names) && count($names) == count($values)) { $metaTags = 配列(); for ($i=0, $limiti=count($names); $i htmlentities($originals[$i]), '値' => $values[$i] ); } } } } それ以外 { if (isset($match) && is_array($match) && count($match) == 3) { $originals = $match[0]; $names = $match[1]; $values = $match[2]; if (count($originals) == count($names) && count($names) == count($values)) { $metaTags = 配列(); for ($i=0, $limiti=count($names); $i htmlentities($originals[$i]), '値' => $values[$i] ); } } } }$result = 配列 ( 'metaTags' => $metaTags ); if(isset($result['metaTags']['キーワード']['値'])) { $info['キーワード']=$result['メタタグ']['キーワード']['値']; } それ以外 { $info['キーワード']=""; } if(isset($result['metaTags']['説明']['値'])) { $info['desc']=$result['metaTags']['説明']['値']; } それ以外 { $info['desc']=""; } $domain=preg_replace('/http:///si', '', $this->url); $ip=@gethostbyname($domain); $ip_arr=explode(".", $ip); if(カウント($ip_arr)==4) { $info['ip']=$ip; } $info を返します。 } パブリック関数 t($string,$o) { for($i=0;$iopen($this->url)){return false;exit;} //首先从html获取编coding preg_match("/request->results,$temp) ? strto lower($temp[1]):""; if($temp[1]!="") { if(in_array($temp[1], $this->charset_arr)) { if($temp[1]=="gb2312") { $tmp_charset=$this->t($this->request->results,$temp[1]); if($tmp_charset==$temp[1]) { $temp[1] を返します; } } それ以外 { $temp[1] を返します; } } } if(!empty($this->request->headers)) { //ヘッダー中取得コード $hstr=strto lower(implode("


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。