Study Area Facebook粉絲團http://www.facebook.com/sataiwan
0 會員 與 1 訪客 正在閱讀本文。
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>顯示資料</title></head><body><?$text=file_get_contents('http://ccs.ncl.edu.tw/ccsenews/b/epaper_content_show.asp?EpaperID=65&ContentTypeID=4&SerialNo=2#Detail4_1');preg_match('/<span [^>]*class="font_s5"[^>]*>(.*?) <\/span>/si',$text,$match);print($match[0]);?></body></html>
我想要抓取書名,以國圖為例:http://ccs.ncl.edu.tw/ccsenews/b/epaper_content_show.asp?EpaperID=65&ContentTypeID=4&SerialNo=2#Detail4_1參考Google上提供的語法,我設計如下:代碼: [選擇]<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>顯示資料</title></head><body><?$text=file_get_contents('http://ccs.ncl.edu.tw/ccsenews/b/epaper_content_show.asp?EpaperID=65&ContentTypeID=4&SerialNo=2#Detail4_1');preg_match('/<span [^>]*class="font_s5"[^>]*>(.*?) <\/span>/si',$text,$match);print($match[0]);?></body></html>但是內容是空白的,請問我是否有遺漏若干重點呢?謝謝~
怎麼不用DOM抓?
php dom html 直接fetch html 來regEx filter,太原始了啦。
<meta http-equiv="Content-Type" content="text/html; charset=big5">
preg_match_all('/<span.*?class="font_s5".*?>(.*?)<\/span>/i',$text,$matches);echo "<pre>";print_r($matches[0]);echo "</pre>";