#!/usr/bin/perl -w

use strict;
use XML::RSS;
use LWP::Simple;

my $page = get('http://www.thesun.co.uk/section/0,,4,00.html');

my $rss = new XML::RSS (version => '1.0');

$rss->channel(title       => 'The Sun: Bizarre',
     	      link        => 'http://www.thesun.co.uk/section/0,,4,00.html',
	      description => 'The Sun: Bizarre');

# Eek! .* is a bit much, though it works.
# Matches top story
if ($page =~ m!<tr><td colspan=\"\d\"><a href=\"(/article/0,,.*\.html)\"><img src=\"http://images.thesun.co.uk/picture/.*\.gif\" alt=\"([^"]*)\"!)
{
	#print "$1, $2";
	$rss->add_item(title => "$2",
	 	       link =>  'http://www.thesun.co.uk' . $1);
}

# Other stories

my @lines = split ("<[tT][Rr]", $page);

foreach (@lines)
{
	if (m!<td style=[^>]*><a (class=\"[^"]+\" )?href=\"(/article/0,,.*\.html)\"[^>]*>([^<]*)</a><br>[\r\n]*<span[^>]*>([^<]*)[\r\n]*<[/]?td!is)	
	{
#		print "$2, $3, $4";
		$rss->add_item(title       => "$3",
			       link        => 'http://www.thesun.co.uk' . $2,
			       description => "$4");
	}
}

print $rss->as_string;
