All pastes #1284909 Raw Edit

randword.pl-0.0.2.3

public text v1 · immutable
#1284909 ·published 2008-12-14 12:18 UTC
rendered paste body
#!/usr/bin/perl
################################################################################
#                                                                              #
# ############################################################################ #
# # Title       : randword.pl                                                # #
# # Description : You're a douche, pc486.                                    # #
# # Coded by    : Justin "HEYO--!" Lee                                       # #
# # Version     : 0.0.2.3                                                    # #
# # Date        : 2008-12-14                                                 # #
# # License     : GNU General Public License v.2                             # #
# #               Copyright (C) 2008  Justin Lee  <kool.name at gmail.com>   # #
# ############################################################################ #
#                                                                              #
# ############################################################################ #
# # This program is free software; you can redistribute it and/or            # #
# # modify it under the terms of the GNU General Public License version 2    # #
# # as published by the Free Software Foundation.                            # #
# #                                                                          # #
# # This program is distributed in the hope that it will be useful,          # #
# # but WITHOUT ANY WARRANTY; without even the implied warranty of           # #
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            # #
# # GNU General Public License for more details.                             # #
# #                                                                          # #
# # You should have received a copy of the GNU General Public License        # #
# # along with this program; if not, write to the Free Software              # #
# # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA            # #
# # 02110-1301, USA.  Or, see: <http://www.gnu.org/licenses/>                # #
# ############################################################################ #
#                                                                              #
################################################################################

# config
my $url = 'http://www.zokutou.co.uk/randomword/index.php';

# script
use strict;
use warnings;
use lib '.';
use HTML::Scrape qw(put);
use LWP::Simple;

my $scraper = new HTML::Scrape(
  Machine => [
     # find the word's table
    { 'tag'     => 'table',
      'require' => { 'width'       => qr/95%/,
                     'border'      => qr/2/,
                     'align'       => qr/center/i,
                     'cellpadding' => qr/8/,
                     'cellspacing' => qr/0/,
                     'bordercolor' => qr/85A1CC/i,
                     'bgcolor'     => qr/#babfFf/i } },
     # find the word's element
    { 'tag'  => 'h4' },
     # grab the word
    { 'text' => put('word') }
  ]
) or die;

# tsv from ScrapeTest.pl is fucking cryptic, you bastard ;)
my ($html) = get($url) or die "Couldn't retrieve: $url";
my ($word) = $scraper->scrape($html,1);
print "Random Word: $word->{'word'}\n";