本帖最后由 523066680 于 2018-1-30 19:40 编辑
- =info
- 查看 bathome 在线会员浏览状态
- 523066680@163.com
- 2018-01
-
- * Version 0.5
- 格式化对齐输出
- =cut
-
- use Modern::Perl;
- use utf8;
- use Encode;
- use Mojo::UserAgent;
- use List::Util qw/max/;
- use Term::ReadKey;
- STDOUT->autoflush(1);
-
- our (@pages, @list, @maxlen);
- our $main = "http://bbs.bathome.net/member.php?action=online&page=";
- my ($ua, $res, $dom);
- $ua = Mojo::UserAgent->new();
- $ua = $ua->max_redirects(5);
-
- get_pages( \@pages, $ua );
- get_online_info( \@list, $_ ) for ( @pages );
-
- #计算每列最大宽度
- for my $col ( 0 .. $#{$list[0]} )
- {
- push @maxlen, max( map { length($list[$_]->[$col]) } ( 0 .. $#list ) );
- }
-
- #输出
- for my $e ( @list )
- {
- for my $col ( 0 .. $#$e )
- {
- printf "%-${maxlen[$col]}s ", $e->[$col] ;
- }
- printf "\n";
- }
-
- ReadKey -1;
-
- sub get_online_info
- {
- my ( $list, $dom ) = @_;
- my @ele;
- my $guest = encode('gbk', "游客");
-
- for my $e ( $dom->find("tr[class]")->each )
- {
- @ele = map { $_->all_text } $e->find('td')->each;
- @ele = map { s/\xa0//g; $_ } @ele; # remove
- #push @$list, \@ele if ( $ele[0] !~/$guest/ ); # 会得到重复的结果
- push @$list, [@ele] if ( $ele[0] !~/$guest/ );
- }
- }
-
- sub get_pages
- {
- my ( $pages, $ua ) = @_;
- my @pgcode;
-
- print "getting page: ", 1;
- $res = $ua->get( $main ."1" )->result;
- $dom = $res->dom;
- push @$pages, $res->dom;
-
- @pgcode = map { $_->text } $dom->at(".pages_btns")->find('a')->each;
- @pgcode = grep { /\d/ } @pgcode; #只选择数字项
-
- for my $code ( @pgcode )
- {
- print ",", $code;
- push @$pages, $ua->get( $main .$code )->result->dom;
- }
- say "\n";
- }
复制代码 排除游客状态,输出示例:- getting page: 1,2,3,4,5,6,7
-
- 老刘1号, 18:03, 浏览帖子, VBS教程&资料, bat、vbs、js 原生混编
- axuku, 18:02, 无效的越权访问, PowerShell原创&转载,
- Ricky_520, 18:02, 回复主题, BAT求助&讨论, 小白求代编写:bat定期运行软件,在线 ...
- pzjsu, 18:01, 无效的越权访问, VBS原创&转载,
- 523066680, 17:59, 查看在线用户, ,
- Hack38, 17:59, 浏览帖子, BAT求助&讨论, [分享]批处理实现windows下自动切换壁 ...
- 13633425027, 17:59, 浏览帖子, BAT教程&资料, [批处理命令一日一教学](6)复制文件 ...
- yhcfsr, 17:56, 浏览论坛首页, ,
- axrme, 17:55, 无效的越权访问, 出题挑战,
复制代码 更新,对齐- getting page: 1,2,3,4,5,6,7,8
-
- 老刘1号 19:34 浏览论坛首页
- tloye 19:32 提示信息/页面跳转 站务交流
- owlnp 19:32 无效的越权访问 开源原创工具
- WHY 19:32 浏览帖子 有偿求助 10元红包求助。
- jwzgy 19:30 无效的越权访问 Python
- lanwa 19:30 浏览帖子 第三方命令行 bat2exe工具Quick Batch File Compile ...
- ykdqg 19:29 无效的越权访问 UNIX/Linux Shell
- fnrsn 19:28 无效的越权访问 第三方命令行
- 思想之翼 19:27 浏览帖子 BAT教程&资料 [系列教程]批处理for语句从入门到精通 ...
复制代码
|