PHP下载网页
来源:互联网 发布:特价专场首页淘宝优站 编辑:程序博客网 时间:2024/05/18 01:20
<?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);
?>
0 0
- PHP下载网页
- PHP下载网页图片
- 用PHP写 下载网页
- 将网页内容用php程序下载下来的方法
- php批量下载网页图片并替换路径为本地
- php实现解析网页并下载图片到本地
- HTML网页设计之PHP下载生成的excel表格
- [php]同步下载html网页下的图片
- 下载网页
- 下载网页
- php下载
- php下载
- 下载PHP
- php在程序中把网页生成word文档并提供下载
- IE浏览器打开网页时提示下载php文件的解决办法
- DedeHttpDown PHP远程下载网页的类,增强版 2013-1-17修改
- PHP 利用 Curl Functions 实现多线程抓取网页和下载文件
- 一步一步分析解决PHP文件下载直接在网页中打开问题
- 内存分配 缓冲区
- spring transaction 失效问题
- Android ndk-stack tool使用
- sublime text 自己常用的快捷键
- Linux makefile 教程 非常详细,且易懂
- PHP下载网页
- hdu 3729 I'm Telling the Truth
- 手机卫士学习06-自定义滚动的TextView实现走马灯效果
- ASCII编码与Unicode编码
- onActivityResult传值
- 新股集合竞价
- 制作dll和测试dll
- 关于apache FTP下载速度慢的解决方案
- 什么是编程语言