PHP DZone 故事信息采集器

让用户向 DZone 提交帖子非常棒,原因如下:

  • 读者对您写的内容有足够的思考,希望与他人分享。
  • 您的博客获得更多读者。
  • 您的博客收入增加。
  • 内链和流量提升可以提高您的搜索引擎排名和 Alexa 排名。
  • 新访问者可能会发表评论,这可能会增强您的文章。

当然还有更多。因此,跟踪 DZone 提供的关于您的文章的信息非常重要。幸运的是,使用一些快速的 PHP 代码,您可以直接从 DZone 获取相关信息。您只需要知道包含您文章的 DZone URL。

代码

/* step 1:  download the page content */
$dzone_content = file_get_contents('http://www.dzone.com/links/f_programming_fast_guide.html');

/* step 2:  parse it! */
$votes_up = get_match('/>(.*)<\/li>/isU',$dzone_content);
$votes_down = get_match('/>(.*)<\/li>/isU',$dzone_content);
$views = get_match('/>(.*)<\/li>/isU',$dzone_content);
$clicks = get_match('/>(.*)<\/li>/isU', $dzone_content);

/* step 3:  echo */
echo 'Up Votes: ',$votes_up,'<br />';
echo 'Down Votes: ',$votes_down,'<br />';
echo 'Views: ',$views,'<br />';
echo 'Clicks: ',$clicks,'<br />';

/* helper:  does regex */
function get_match($regex,$content)
{
	preg_match($regex,$content,$matches);
	return $matches[1];
}

请注意:每次使用此脚本都会增加 DZone 的“浏览量”统计数据,因此如果您打算保持准确的统计数据,请记录页面请求的数量并从总数中减去该数量。

赞(0) 打赏

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏