首页 > 代码库 > PHP下载网页
PHP下载网页
<?php
/*
author:whq
作用:获取网页的内容
*/
include "../Snoopy/Snoopy.class.php";
class CuteCrawler
{
/*
通过fopen来下载网页
*/
public function getContentByFopen($url)
{
$f = fopen($url, ‘r‘);
$content = ‘‘;
if($f)
{
while(($buffer = fgets($f, 10240)) != false)
{
$content = $content.$buffer;
}
fclose($f);
}
return $content;
}
public function getContentByFilegetcontent($url)
{
$content = file_get_contents($url);
return $content;
}
/*
通过CURL下载网页
*/
public function getContentByCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
public function getContentSnoopy($url)
{
$snoopy = new Snoopy;
$snoopy->fetchlinks($url);
return $snoopy->results;
}
}
$url = "http://www.kugou.com/yy/special/single/18920.html";
$crawler = new CuteCrawler();
$content = $crawler->getContentByFopen($url);
$con1 = $crawler->getContentByFilegetcontent($url);
$con2 = $crawler->getContentByCurl($url);
$con3 = $crawler->getContentSnoopy($url);
//echo ‘content:‘.$content;
// echo $con1;
// var_dump($con1);
print_r($con3);
?>
/*
author:whq
作用:获取网页的内容
*/
include "../Snoopy/Snoopy.class.php";
class CuteCrawler
{
/*
通过fopen来下载网页
*/
public function getContentByFopen($url)
{
$f = fopen($url, ‘r‘);
$content = ‘‘;
if($f)
{
while(($buffer = fgets($f, 10240)) != false)
{
$content = $content.$buffer;
}
fclose($f);
}
return $content;
}
public function getContentByFilegetcontent($url)
{
$content = file_get_contents($url);
return $content;
}
/*
通过CURL下载网页
*/
public function getContentByCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
public function getContentSnoopy($url)
{
$snoopy = new Snoopy;
$snoopy->fetchlinks($url);
return $snoopy->results;
}
}
$url = "http://www.kugou.com/yy/special/single/18920.html";
$crawler = new CuteCrawler();
$content = $crawler->getContentByFopen($url);
$con1 = $crawler->getContentByFilegetcontent($url);
$con2 = $crawler->getContentByCurl($url);
$con3 = $crawler->getContentSnoopy($url);
//echo ‘content:‘.$content;
// echo $con1;
// var_dump($con1);
print_r($con3);
?>
PHP下载网页
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。