The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::GoKGS - KGS Go Server (http://www.gokgs.com/) Scraper

SYNOPSIS

  use WWW::GoKGS;

  my $gokgs = WWW::GoKGS->new;

  # Game archives
  my $gameArchives1 = $gokgs->scrape( '/gameArchives.jsp?user=foo' );
  my $gameArchives2 = $gokgs->game_archives->query( user => 'foo' );

  # Top 100 players
  my $top100Players1 = $gokgs->scrape( '/top100.jsp' );
  my $top100Players2 = $gokgs->top_100->query;

  # List of tournaments 
  my $tournList1 = $gokgs->scrape( '/tournList.jsp?year=2014' );
  my $tournList2 = $gokgs->tourn_list->query( year => 2014 );

  # Information for the tournament
  my $tournInfo1 = $gokgs->scrape( '/tournInfo.jsp?id=123' );
  my $tournInfo2 = $gokgs->tourn_info->query( id => 123 );

  # Tournament entrants
  my $tournEntrants1 = $gokgs->scrape( '/tournEntrans.jsp?id=123&sort=n' );
  my $tournEntrants2 = $gokgs->tourn_entrants->query( id => 123, sort => 'n' );

  # Tournament games
  my $tournGames1 = $gokgs->scrape( '/tournGames.jsp?id=123&round=1' );
  my $tournGames2 = $gokgs->tourn_games->query( id => 123, round => 1 );

DESCRIPTION

This module is a KGS Go Server (http://www.gokgs.com/) scraper.

This class maps a URI preceded by http://www.gokgs.com/ to a proper scraper. The supported resources on KGS are as follows:

KGS Game Archives (http://www.gokgs.com/archives.jsp)

Handled by WWW::GoKGS::Scraper::GameArchives.

Top 100 KGS Players (http://www.gokgs.com/top100.jsp)

Handled by WWW::GoKGS::Scraper::Top100.

KGS Tournaments (http://www.gokgs.com/tournList.jsp)

Handled by WWW::GoKGS::Scraper::TournList, WWW::GoKGS::Scraper::TournInfo, WWW::GoKGS::Scraper::TournEntrants and WWW::GoKGS::Scraper::TournGames.

ATTRIBUTES

$UserAgent = $gokgs->user_agent

Returns an LWP::UserAgent object which is used to GET the requested resource. This attribute is read-only.

  use LWP::UserAgent;

  my $gokgs = WWW::GoKGS->new(
      user_agent => LWP::UserAgent->new(
          agent => 'MyAgent/1.00',
      ),
  );
$CodeRef = $gokgs->html_filter

Returns an HTML filter. Defaults to an anonymous subref which just returns the given argument (sub { $_[0] }). The callback is called with an HTML string. The return value is used as the filtered value. This attribute is read-only.

  my $gokgs = WWW::GoKGS->new(
      html_filter => sub {
          my $html = shift;
          $html =~ s/<.*?>//g; # strip HTML tags
          $html;
      },
  );
$CodeRef = $gokgs->date_filter

Returns a date filter. Defaults to an anonymous subref which just returns the given argument (sub { $_[0] }). The callback is called with a date string such as 2014-05-17T19:05Z. The return value is used as the filtered value. This attribute is read-only.

  use Time::Piece qw/gmtime/;

  my $gokgs = WWW::GoKGS->new(
      date_filter => sub {
          my $date = shift; # => "2014-05-17T19:05Z"
          gmtime->strptime( $date, '%Y-%m-%dT%H:%MZ' );
      },
  );
$GameArchive = $gokgs->game_archives

Returns a WWW::GoKGS::Scraper::GameArchives object. This attribute is read-only.

$Top100 = $gokgs->top_100

Returns a WWW::GoKGS::Scraper::Top100 object. This attribute is read-only.

$TournList = $gokgs->tourn_list

Returns a WWW::GoKGS::Scraper::TournList object. This attribute is read-only.

$TournInfo = $gokgs->tourn_info

Returns a WWW::GoKGS::Scraper::TournInfo object. This attribute is read-only.

$TournEntrants = $gokgs->tourn_entrants

Returns a WWW::GoKGS::Scraper::TournEntrants object. This attribute is read-only.

$TournGames = $gokgs->tourn_games

Returns a WWW::GoKGS::Scraper::TournGames object. This attribute is read-only.

METHODS

$HashRef = $gokgs->scrape( '/gameArchives.jsp?user=foo' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/gameArchives.jsp?user=foo' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/gameArchives.jsp?user=foo' );
  my $gameArchives = $gokgs->game_archives->scrape( $uri );

See WWW::GoKGS::Scraper::GameArchives for details.

$HashRef = $gokgs->scrape( '/top100.jsp' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/top100.jsp' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/top100.jsp' );
  my $top100 = $gokgs->top_100->scrape( $uri );

See WWW::GoKGS::Scraper::Top100 for details.

$HashRef = $gokgs->scrape( '/tournList.jsp?year=2014' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/tournList.jsp?year=2014' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/tournList.jsp?year=2014' );
  my $tournList = $gokgs->tourn_list->scrape( $uri );

See WWW::GoKGS::Scraper::TournList for details.

$HashRef = $gokgs->scrape( '/tournInfo.jsp?id=123' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/tournInfo.jsp?id=123' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/tournInfo.jsp?id=123' );
  my $tournInfo = $gokgs->tourn_info->scrape( $uri );

See WWW::GoKGS::Scraper::TournInfo for details.

$HashRef = $gokgs->scrape( '/tournEntrants.jsp?id=123&s=n' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/tournEntrants.jsp?id=123&s=n' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/tournEntrants.jsp?id=123&s=n' );
  my $tournEntrants = $gokgs->tourn_entrants->scrape( $uri );

See WWW::GoKGS::Scraper::TournEntrants for details.

$HashRef = $gokgs->scrape( '/tournGames.jsp?id=123&round=1' )
$HashRef = $gokgs->scrape( 'http://www.gokgs.com/tournGames.jsp?id=123&round=1' )

A shortcut for:

  my $uri = URI->new( 'http://www.gokgs.com/tournGames.jsp?id=123&round=1' );
  my $tournGames = $gokgs->tourn_games->scrape( $uri );

See WWW::GoKGS::Scraper::TournGames for details.

SEE ALSO

Web::Scraper

AUTHOR

Ryo Anazawa (anazawa@cpan.org)

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.