iThome online | iThome Blog | iThome周刊訂閱

載入中...

chikaeyang

IT邦初學者
10級

PHP正規表達式的問題
標籤:php

使用php抓取無名分類相簿的資料

網址如下
http://www.wretch.cc/album/?func=hot&hid=0&class_id=9

目前要抓的資料是中間4x5的圖片、網址、名稱

下面為原始碼大概的資料

<li>
<div class="image_link">
<a href="http://tw.rd.yahoo.com/referurl/wretch/album/score/0/9/*http://www.wretch.cc/album/album.php?id=babyeri&amp;book=63" target="_blank"><img src="http://f4.wretch.yimg.com/babyeri/63/thumbs/t1834944605.jpg" alt="E˙宅" /><cite></cite></a>
</div>
<div class="grid">
<a href="http://tw.rd.yahoo.com/referurl/wretch/album/score/0/9/*http://www.wretch.cc/album/album.php?id=babyeri&amp;book=63" target="_blank">babyeri</a>
<strong>E˙宅</strong>

</div>
</li>
<li>
<div class="image_link">
<a href="http://tw.rd.yahoo.com/referurl/wretch/album/score/0/9/*http://www.wretch.cc/album/album.php?id=youpkcs&amp;book=16" target="_blank"><img src="http://f9.wretch.yimg.com/youpkcs/16/thumbs/t1249649407.jpg" alt="男人看了會跳起來" /><cite></cite></a>
</div>
<div class="grid">
<a href="http://tw.rd.yahoo.com/referurl/wretch/album/score/0/9/*http://www.wretch.cc/album/album.php?id=youpkcs&amp;book=16" target="_blank">youpkcs</a>

<strong>男人看了會跳起來</strong>
</div>
</li>


如果使用preg_match_all那麼正規表達式該如何下才能抓取這些資料呢?

並將這20筆資料各別代出

謝謝

收藏到:發佈到twitter       
解決時間:2008-10-06 21:46:57
發問時間:2008-10-03 12:11:28

什麼是dom

2008-10-04 15:12:33 補充

brianc
你的設定只能抓到圖片而已
應該有圖片、網址、說明

2008-10-06 11:20:26 補充

最佳解答(發問者自選)
4

回答:brianc ( IT邦初學者8級 )

時間:2008-10-06 11:51:20

$html = file_get_contents('http://www.wretch.cc/album/?func=hot&hid=0&class_id=9');
$pattern = '|<a href="(.*)" target="_blank"><img src="(.*)" alt="(.*)" /><cite></cite></a>|';
preg_match_all($pattern, $html, $matches);
print_r($matches);

PHP正規表達式的問題
回答:brianc( IT邦初學者8級 )
時間:2008-10-06 11:11:57
***回答已移除***

回應

請填寫您的回應,長度限為1,000個字,回應不計點數,也不限使用次數



 

檢舉違規

違規事項:

*補充檢舉理由(可省略),字數不可超過100字

推薦

推薦理由:


*給回答者的鼓勵(可不填),字數不可超過100字

熱門標籤


free counters