用PHP抓取数据
用PHP实现简单的数据抓取
方法一:
<?php
$urlstr = file_get_contents("http://www.baidu.com");
$urlstr = htmlspecialchars($urlstr);
print_r($urlstr);
?>
方法二:(需要打开curl扩展)
注意:打开curl扩展时,一定要看看php加载php.ini文件的路径,通过phpinfo()函数就可以看到php挂载的php.ini文件路径。
<?php
//初始化curl
$ch = curl_init() or die (curl_error());
curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com/s?wd=php"); //要求CURL返回数据
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //执行请求
$result = curl_exec($ch) or die (curl_error()); //取得返回的结果,并显示
//echo $result;
$result = htmlspecialchars($result);
print_r($result);
curl_close($ch);
?>
得到页面静态源代码后,就可以通过正则帅选你想要的结果,很方便。
相关文档:
php有一组进程控制函数,使得php能在*nix系统中实现跟c一样的创建子进程、使用exec函数执行程序、处理信号等功能。
引用
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a ......
http://www.oracle.com/technology/global/cn/pub/notes/technote_php_instant.html
为 Linux 和 Windows 安装 PHP 和 Oracle 10g Instant Client
作者:Christopher Jones,甲骨文公司的咨询技术人员
发布日期:2004 年 12 月
Oracle 10g Instant Client(免费下载)是PHP 与远程 Oracle 数据库连接的最简单方式,它 ......
安装环境为windows操作系统,由于我同时需要asp+mssql(access)的调试环境,所以就在windows平台下增加apache+php+mysql的调试环境,双环境同时存在,方便我随时切换。
Apache的安装与配置
打开apache官方网站 http://archive.apache.org/dist/httpd/binaries/ ......
1、使用单引号括起来的字符串
当使用双引号来括字符串时,PHP解释器会对其进行变量替换、转义等操作,如
“\n”。如果只想输出一个基本的字符串,用单引号会节省一些资源。当然,如果需要进行变量替换的,那就必须用双引号了。
2、字符串的输出
以下哪一条语句的运行速度最快?
print “Hi my name is ......
其实这个的主要部分并不是一个jquery,但是必须使用到
php程序部分,也只需要这个一个php程序就可以了
www.corange.cn亲测
<?php
header("Content-Type: text/html; charset=utf-8");
@header( "Cache-Control: no-cache, must-revalidate" );
@header( "Pragma: no-cache" );
@header( "Last-Modified: " ......