I just whipped up a quick bit of code to scrape the TVGuide listings for a given zipcode and subscriber type (Cable, Sattelite, Antenna), and dump them to the screen (for now). I'm trying to figure out a better way to format these, visually, so that at some point, they end up as HTML, in a display that is NOT using HTML tables to display them (no CSS allowed either).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.