作者foxzgerald (O⊥M)
看板PHP
标题Re: [请益] 抓取网页html原始码
时间Wed May 16 17:19:36 2007
※ 引述《NCK (守备范围:18~25岁)》之铭言:
: <?php
: $url = $_GET['URL'].$_POST['words'];
: $ch = curl_init(); //初始化curl,要准备开始抓网页
: curl_setopt($ch, CURLOPT_URL, $url); //告诉url要抓的是第一行的网页
: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //不要将抓回来的网页秀到萤幕上,
: //等等我们要继续分析
: $content = curl_exec($ch); //抓吧,然後将资料存到$content
^^^^^^^^^^^^^^^^^^^^^^^^^
其实 $content 的内容就是原始的 html 字串,
所以应该针对 $content 做 parse 才对
: curl_close($ch);
: $html = htmlentities($content);
^^^^^^^^^^^^^^^^^^^^^^
这麽做则是去除 html 的"特性"--把"标签"转为一般的字串。
如果你要做的是把 html 原始码、或许帮标签上色之後.
完整地秀在网页上... 那才需要用 htmlentities() 把 "<>" 转成 "<>"
: $tok = strtok($html, "<h3>posting history</h3>");
: echo $tok;
: ?>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.119.199.121