作者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)