Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Formatting parsed TV Guide HTML listings

by hacker (Priest)
on Jun 19, 2003 at 23:25 UTC ( [id://267385]=perlquestion: print w/replies, xml ) Need Help??

hacker has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Formatting parsed TV Guide HTML listings
by dws (Chancellor) on Jun 19, 2003 at 23:59 UTC
    Some other ideas? Some other module I might leverage?

    Check in to WWW::Mechanize. It automates much of what you're doing to get to the content you need to parse.

Re: Formatting parsed TV Guide HTML listings
by Beatnik (Parson) on Jun 20, 2003 at 00:07 UTC
    Small note: Johan Van den Brande was more or less forced to take his TV Listing scraping module off CPAN because of the terms of use of the site he scrapped from. Just be carefull

    Greetz
    Beatnik
    ... I'm belgian but I don't play one on TV.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://267385]
Approved by dash2
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found