Here's the working code I have so far, try it out.
use strict; use LWP::UserAgent; use HTTP::Cookies; use HTML::TableExtract; # Define your service preference here # Cable = 1 # Sattelite Dish = 2 # Broadcast/Antenna = 3 my $service = '1'; my $zip = '02891'; $service = $service == 1 ? 'Cable' : $service == 2 ? 'Satellite' : 'Broadcast'; my $cookiefile = 'tvguide.cookies'; my $ua = 'Mozilla/4.0 (Windows NT 5.0)'; my $browser = LWP::UserAgent->new( agent => "$ua", env_proxy => 1, timeout => 30, ); $browser->cookie_jar(HTTP::Cookies->new( 'file' => $cookiefile, 'ignore_discard' => 1, 'autosave' => 1,)); my $url = 'http://tvguide.com/listings/setup/'; $url .= "Localize${service}.asp"; $url .= "?I=&ZipCode=${zip}&url="; print "Fetching $service listings for zipcode $zip\n"; my $response = $browser->get($url); my $content = $response->content; my $te = new HTML::TableExtract(depth => 3, count => 4); $te->parse($content); foreach my $table ($te->tables) { foreach my $row ($te->rows($table)) { print join(',', @$row), "\n"; } }
The end goal should return a nice easy-to-read set of listings, not using HTML tables, so they can be displayed on a Palm device. It's more of a proof-of-concept for now, but I'm looking for some ideas on how I might be able to format this better.
Perhaps keeping the date/time rows above each listing itself?
Some other ideas? Some other module I might leverage? Thanks everyone.
In reply to Formatting parsed TV Guide HTML listings by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |