作者dk29 (柯呆)
看板PHP
標題[請益] 關於PHP抓網頁的程式有問題
時間Mon Mar 16 13:23:17 2009
<?php
//$fp=fopen('
http://tw.search.yahoo.com/search?p=121&fr=yfp&ei=utf-8&v=0','r');
$fp=fopen('
http://www.yahoo.com.tw','r');
while ($line=fgets($fp,1024)){
//echo $line;
//if(preg_match_all('/<.*?a.*?href=\s*?[\'"](*+)[\'"].*?\s>(*+)<\/.*?a.*>/i',$line,$matches))
preg_match_all("/<.*?a.*?href=.*?[\'\"](.*?)[\'\"].?>(.*?)<\/.*?a.*?>/i",$line,$matches);
}//while
for($i=0;$i<count($matches[0 ]);$i++){
echo "name:".$matches[2 ][$i]."\n";
echo "url:".$matches[1 ][$i]."\n";}
}
fclose($p);
?>
這是我們寫的抓網頁的程式
可是一直都跑不出東西
有人可以幫我們看看嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.130.189.14
1F:推 buganini :你的while.... 03/16 14:19
2F:→ buganini :把preg_match_all拿到迴圈外面 用file_get_contents 03/16 14:20
3F:→ buganini :取代while_fgets讀整個內容 03/16 14:20
4F:→ buganini :不然match總是會被最後一串的東西蓋掉 03/16 14:21