search
Homephp教程php手册抓取网站第N条评论的作者

抓取网站第N条评论的作者

Jun 06, 2016 pm 08:08 PM
authorcrawlarticlewebsiteComment

今天声儿在上一篇文章中抢第100条评论没抢到,给了我一个灵感,就是抓取网站历史上第N条评论的作者,比如抓取第1000条评论的作者,也就是查询第1000条评论是谁发出的,找出谁是这个幸运之星~ 先上效果,(白色框框里面是鼠标放上去显示的title内容,也可以去小蝴蝶的

今天声儿在上一篇文章中抢第100条评论没抢到,给了我一个灵感,就是抓取网站历史上第N条评论的作者,比如抓取第1000条评论的作者,也就是查询第1000条评论是谁发出的,找出谁是这个幸运之星~
先上效果,(白色框框里面是鼠标放上去显示的title内容,也可以去小蝴蝶的留言板围观)


把如下代码扔到你想显示的地方即可
<?php $args = array(
	'order' => 'ASC',//排序orderby的默认值是comment_date_gmt,所以只需调整order为倒序即可实现从旧往新输出
	'number' => '1',//显示一条
	'offset' => 99,  //这里很重要,在本组函数中表示的意思是指在第一条评论之后99条的评论,也就是第100条 
	//'type' => 'comment', //如果你想仅仅统计不带pingbacks的评论,请把这句前面的//去掉 
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo('第100条:<a href="'.%20get_comment_link(%24comment->comment_ID).'" title="'.mysql2date('在Y-m-d说:',$comment->comment_date). strip_tags($comment->comment_content). '">'.$comment->comment_author.'</a>');
endforeach;
?>

用array是为了方便用注释给大家解释,如果大家喜欢短一点的,下面这段代码效果同上(是的,其实我就是想让文章更长一点,怎么地!)

<?php $comments = get_comments('number=1&offset=99&order=ASC');
foreach($comments as $comment) :
echo('第100条:<a href="'. get_comment_link($comment->comment_ID).'" title="'.mysql2date('在Y-m-d说:',$comment->comment_date). strip_tags($comment->comment_content). '">'.$comment->comment_author.'');
endforeach;
?>

好了,为了让这个功能派上用场,小蝴蝶即日起开展盖楼大赛(我好无聊哦),每第N000个幸运好基友都有机会....
上面省略号中的内容我想了很久无果,所以大家踊跃发言说说给什么福利比较好呢?
话说回来发言还是要发言的,但代码也是要看的哦,唔要本末倒置咗!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.