From 0e5402808641dc2d9eb2d586d0665d9391dca070 Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Mon, 7 Apr 2014 20:21:17 +0100 Subject: [PATCH] Commit after Sunday's work, which I sort of forgot Hence the less useful commit message. --- parse-route.pl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 parse-route.pl diff --git a/parse-route.pl b/parse-route.pl new file mode 100644 index 0000000..0995bf3 --- /dev/null +++ b/parse-route.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use WWW::Mechanize; +use HTML::TreeBuilder; + +my $mech = WWW::Mechanize->new(); + +my $query_site = "http://traintimes.org.uk"; + +die "Usage: $0 \n" + unless( scalar( @ARGV ) == 4 ); + +my ( $src, $dest, $date, $depart ) = @ARGV; + +print "Finding routes from $src to $dest on $date at $depart\n"; + +my $url = "${query_site}/${src}/${dest}/${depart}/${date}"; +print "Checking $url\n"; + +my $stops = get_stops( $url ); + +sub get_stops { + my ( $url ) = @_; + + $mech->get( $url ); + + my $tree = HTML::TreeBuilder->new_from_content( $mech->content ); + + my $first_stop = $tree->look_down( '_tag', 'li', 'id', 'result0' ); + my $details_url = $first_stop->look_down( '_tag', 'a', 'class', 'calling_link' )->attr('href'); + my $ticket_type = $first_stop->look_down( '_tag', 'span', 'class', 'fare-type tooltip')->look_down('_tag', 'a')->as_text; + my $ticket_price = ( $first_stop->look_down( '_tag', 'label' ) )[0]->as_text; + print "Ticket type: $ticket_type\n"; + print "Cost: $ticket_price\n"; + print "stopping points URL: $details_url\n"; +} -- 2.39.5