作者qk5669 (銘)
看板PHP
標題[請益] phpquery抓網頁
時間Thu Mar 22 11:43:58 2012
最近抓網頁的時候
遇到一個網頁內有javascript
內容如下
<SCRIPT LANGUAGE="JavaScript">
function open_zoom_window()
{
OpenWindow=window.open("", "zoom_window", "height=, width=, toolbar=no,
scrollbars=no, menubar=no");
OpenWindow.document.write("<TITLE>Euro-Pro NJ600 3-Speed Blender</TITLE>")
OpenWindow.document.write("<BODY BGCOLOR=white>")
OpenWindow.document.write("<table width=100% height=100% valign=center>")
OpenWindow.document.write("<tr align=center><td><img
src=\"
http://img.epinions.com\"></td></tr>")
OpenWindow.document.write("</table>")
OpenWindow.document.write("</BODY>")
OpenWindow.document.write("</HTML>")
OpenWindow.document.close()
self.name="main"
}
</SCRIPT>
因為javascript內有</BODY>
造成pq()在過濾tag的時候
到這邊就認為網頁結束了
不會再往下搜尋
不知道有沒有方法可以解決
讓他可以正確地搜尋整個網頁
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.128.14
1F:→ chrisQQ:如果中間那段 javascript 你不要的話,就先把他取代掉 03/22 13:00
2F:→ chrisQQ:在丟進 phpquery 03/22 13:00
那段確實不需要 最近才開始用phpquery
我是這樣寫
$url='網址';
curl_setopt($curl, CURLOPT_URL, $url);
$profile=curl_exec($curl);
$pq = phpQuery::newDocument($profile)
然後再用pq去過濾
請問要怎麼一開始就把它取代掉
※ 編輯: qk5669 來自: 140.113.73.167 (03/22 13:16)
※ 編輯: qk5669 來自: 140.113.73.167 (03/22 13:20)
3F:推 kerash:取得 profile 時把 <script> 用 regexp 濾掉 03/22 13:43
4F:推 world294:用 Zend_Dom & Zend_Http 比較方便 03/22 14:45
最後我用preg_replace()和regexp把內容過濾掉
順利撈出資料
感謝各位幫忙
※ 編輯: qk5669 來自: 58.114.219.69 (03/24 14:55)