php抓取alexa网页内容 提取站点统计信息
任务:根据输入的域名 统计以下三个数据,第一:全球排名;第二:用户量(月平均值);第三:
人均页面访问量(月平均值)。
思路:使用get_file_contents提取出网页内容,再根据正则表达式进行内容的筛选。
核心函数如下:
<?php
/*
the function of getting aleax data
@param string partten ;the url set
@return array partten ;
*/
function get_alexa_data($url)
{
$a_url = explode(PHP_EOL,$url);
$index = count($a_url);
if(function_exists('file_get_contents'))
{
$result = array();
$pattern = "|<div\\sclass=\"data[^\"]+?\">[^>]*?>[^>]*?([\\d,]+)\\s*?</div>[\\S\\s]*?id=\"reach[\\S\\s]*?<th>1".
"\\smonth[\\S\\s]*?class=\"avg.*?([\\d\\.]+)</td[\\S\\s]*?id=\"pageviews_per_user\"[\\S\\s]*?".
"1\\smonth[\\S\\s]*?class=\"avg.*?([\\d\\.]+)</td|";
for($i = 0; $i < $index; $i++)
{
if(!empty($a_url[$i]))
{
$content = file_get_contents('http://www.alexa.com/siteinfo/'.$a_url[$i]);
if(!preg_match($pattern,$content,$result[$a_url[$i]]))
$result[$a_url[$i]]=array('Not Found','Not Found','Not Found','Not Found');
}
}
}
else
die("the function file_get_contents not found!");
return $result;
}
?>
改变上面的正则表达式,可以满足自己的另外要求。
上面函数使用的前置条件是:alexa提供的查询网址格式'http://www.alexa.com/siteinfo/‘不变。
使用例程:
<table>
<tr>
<td>site</td><td>全球排名</td><td>用户量(月平均值)</td><td>人均页面访问量(月平均值)</td>
</tr>
<?php
$alexa = get_alexa_data($_POST['url']);
foreach($al
相关文档:
一:结构和调用(实例化):
class className{} ,调用:$obj = new className();当类有构造函数时,还应传入参数。如$obj = new className($v,$v2...);
二:构造函数和析构函数:
1、构造函数用于初始化:使用__construct(),可带参数。
2、但析构函数不能带参数(用于在销去一个类之前执行一些操作或功能)。析构函数用 ......
1.php数组基础:
<?php
$ary2 = "zqhung_hongzequan_zqhong";
$arr3 =explode("_",$ary2);//拆分字符串
echo $arr3[1];//打印出来的结果是hongzequan
$ary1 = array("aa","bb");
$ary1[0]="zqhung";//修改数组中的值
echo $ary1[0],"<br>";//打印出来的结果是zqhung
$ary3 = array("id"=>55);
......
最近在写一个 前台基于 javascript. 的客户端 服务器端PHP 的分析系统。
原先计划使用XML为数据交互基础 但是最终还是选用较轻量级的JSON最为数据交互基础。
首先介绍json的格式
json 说简单其实是一种数据格式 更简单的可以看做简单的数组。
实例 (一)
<script>
var jsonArray=[
......
准备:
lighttpd-1.4.15.tar.gz
php-4.4.2.tar.gz
mysql-5.0.20a.tar.gz
开始:
1 编译安装lighttpd
# tar zxvf lighttpd-1.4.15.tar.gz
# cd lighttpd-1.4.15
# ls
# ./configure --prefix=/usr/local/lighttpd //此部无法编译时提示安装prce-devel
#&nbs ......
设置数据库连接
<?php
/**
* @author [斯人]
* @date 2010/6/1/10:16
* @
*
*/
define("RDFAPI_INCLUDE_DIR", "E:/siren/rdfapi-php/api/");
include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
//连接到MSAccess数据库(rdf_db DSN)的使用连接设置
......