|
<?
//采集首頁地址
$url="http://emotion.pclady.com.cn/skills/";
//獲取頁面代碼
$rs=file_get_contents($url);
//設(shè)置匹配正則
//$fp=fopen("text.txt","a");
//$fw=fwrite($fp,$rs);
//fclose($fp);
/*<I class=titles><A
target=_blank>留住你身邊的好男人</A></I>*/
$preg='/<i/s+class=/"titles/"><a/s+href=/"[^>]+/">(.*)<//a><//i>/i';
//進(jìn)行正則搜索
preg_match_all($preg,$rs,$title);
//計(jì)算標(biāo)題數(shù)量
$count=count($title[0]);
echo $count."<br>";
//通過標(biāo)題數(shù)量進(jìn)行內(nèi)容采集
for ($i=0;$i<$count;$i++){
//設(shè)置內(nèi)容頁地址
$pr='/<a/s+href=/"[^>]+/">/isU';
preg_match_all($pr,$title[0][$i],$jurl);
$substr=substr($jurl[0][0],9);
$curl=substr($substr,0,-18);
//獲取內(nèi)容頁代碼
$c=file_get_contents($curl);
//設(shè)置內(nèi)容頁匹配正則
$pc='/<a/s+href=/"[^>]+/">/i';
//進(jìn)行正則匹配搜索
preg_match($pc,$c,$content);
//輸出標(biāo)題
echo $title[0][$i]."<br>";
echo $title[1][$i]."<br>";
$concount=count($content[0]);
echo $concount."<br>";
echo $content[0][0];
for ($j=0;$j<$concount;$j++){
}
}
?>
通過檢測,$c已經(jīng)是內(nèi)容頁的數(shù)據(jù)流了,可是$pc這個的正則表達(dá)式為什么只匹配<這個字符其他的都沒有呢,是因?yàn)槲疑厦嬗昧藄ubsrt()函數(shù)嗎?還是什么問題?麻煩各位大俠指點(diǎn)迷津啊?
php技術(shù):php 信息采集程序代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。