简单爬虫,查博客浏览量

简单的字符串操作,稍微有些不严谨,但还可以修改。直接运行下面的yeshu()方法就可以。

yeshu("http://www.cnblogs.com/cyrfr/"); //博客园首页地址,一定是进去有文章那那个页面

function yeshu($n)
{
	$html = file_get_contents($n);  
	$foun="default.html?page=";
	if(strpos($html,$foun))
	{
		$d= (strpos($html,$foun))+18; 
		$founend='">下一页';
		$e= (strpos($html,$founend));  
		$lent = $e-$d;
		$page=substr($html,$d,$lent); 
		$url = $n.$foun.$page;
		$htm = file_get_contents($url);  
		$str = "<div class=\"pager\">";
		$strend = "页: <a href";
		$f=strpos($htm,$str)+25;
		$g=strpos($htm,$strend);
		$chang = $g-$f;
		$xunhuan =  substr($htm,$f,$chang); 
	}
	else
	{
		$xunhuan = 1;
	}
	zongshu($xunhuan,$n);
	
}

function zongshu($nn,$main){
	$num = 0;
	for($i=1;$i<=$nn;$i++)
	{
		$url = $main."default.html?page=".$i;
		$html = file_get_contents($url); 
		while(strpos($html,"阅读("))
		{
			$find="阅读(";  
			$b= (strpos($html,$find))+7;
			$c= (strpos($html,") 评论"));
			$lenth = $c-$b;
			$num+= substr($html,$b,$lenth); 
			$html = substr($html,$c+8);
		} 
	}	
	echo $num;
}

  

转载于:https://www.cnblogs.com/cyrfr/p/6771063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值