[請益] phpquery抓網頁

看板PHP作者 (銘)時間13年前 (2012/03/22 11:44), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/1
最近抓網頁的時候 遇到一個網頁內有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=\"")" rel="nofollow">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

03/22 13:00, , 1F
如果中間那段 javascript 你不要的話,就先把他取代掉
03/22 13:00, 1F

03/22 13:00, , 2F
在丟進 phpquery
03/22 13:00, 2F
那段確實不需要 最近才開始用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)

03/22 13:43, , 3F
取得 profile 時把 <script> 用 regexp 濾掉
03/22 13:43, 3F

03/22 14:45, , 4F
用 Zend_Dom & Zend_Http 比較方便
03/22 14:45, 4F
最後我用preg_replace()和regexp把內容過濾掉 順利撈出資料 感謝各位幫忙 ※ 編輯: qk5669 來自: 58.114.219.69 (03/24 14:55)
文章代碼(AID): #1FQg00MR (PHP)
文章代碼(AID): #1FQg00MR (PHP)