Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php file_get_contents函数抓取页面信息的代码

php file_get_contents函数抓取页面信息的代码

发布时间:2015-08-24   编辑:www.jquerycn.cn
采用php file_get_contents函数抓取页面数据,这里为大家举个例子。例如,访问55bbs论坛,抓取首页中所有h3标记内的元素。

采用php file_get_contents函数抓取页面数据,这里为大家举个例子。

例如,访问55bbs论坛,抓取首页中所有h3标记内的元素。
 

复制代码 代码示例:
<?php
$url="http://bbs.55bbs.com";
$contents=@file_get_contents($url);
//preg_match_all("/<p class=\"right forumcount\">(.*?)<\/p>/is",$contents,$content);
preg_match_all("/<h3>(.*?)<\/h3>/is",$contents,$content);
print_r($content[0]);
?>

对于较为复杂点的页面抓取,可以考虑采用curl的方法,具体可以参考如下的文章:
PHP中用CURL伪造IP来源的方法
php使用curl判断远程文件是否存在的代码
php使用curl伪造IP来源的代码
php模拟登录qq邮箱(curl命令详解)
php curl 学习总结
curl命令模拟表单上传文件

另外,有关php file_get_contents函数的用法,可以参考如下的文章:
php file_get_contents函数代理获取远程页面的代码
php file_get_contents函数的使用问题
PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
php使用socket、curl、file_get_contents方法POST数据的实例
http://www.w3school.com.cn/php/func_filesystem_file_get_contents.asp

您可能感兴趣的文章:
php file_get_contents抓取页面信息的代码
php file_get_contents函数抓取页面信息的代码
PHP 抓取内容中图片并下载保存的代码
PHP读写文件生成HTML的代码举例
php读取远程文件的三种方法分享
php中curl、fsocket、file_get_content函数比较
php file_get_contents函数的使用问题
PHP fopen/file_get_contents与curl性能比较
php 获取远程网页内容简单函数
php file_get_contents 设置代理抓取页面示例

[关闭]