龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP抓取网页代码示例

时间:2014-06-19 15:12来源:网络整理 作者:网络 点击:
分享到:
PHP抓取网页代码示例 **[PHP]代码**```{.php}//PHP(前提是装了curl):$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, quot;http://outofmemory.cn/quot;);curl_setopt ($ch, CURLOPT_REFERER, quot;http://outofmemory.cn/quot;);curl_exec

[PHP]代码

//PHP(前提是装了curl):
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://outofmemory.cn/");
curl_setopt ($ch, CURLOPT_REFERER, "http://outofmemory.cn/");
curl_exec ($ch);
curl_close ($ch);

//PHP(不装curl用sock)
$server = 'blog.qita.in';
$host      = 'blog.qita.in';
$target    = '/xxx.asp';
$referer = 'http://blog.qita.in/';      // Referer
$port      = 80;
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp) 
{
     echo "$errstr ($errno)<br />\n";
} 
else 
{
          $out = "GET $target HTTP/1.1\r\n";
          $out .= "Host: $host\r\n";
          $out .= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEG\r\n";
          $out .= "Referer: $referer\r\n";
          $out .= "Connection: Close\r\n\r\n";
          fwrite($fp, $out);
          while (!feof($fp)) 
          {
                  echo fgets($fp, 128);
          }
          fclose($fp);
}
精彩图集

赞助商链接