Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

miyagawa (1653)

miyagawa
  (email not shown publicly)
http://bulknews.vox.com/
AOL IM: bulknews (Add Buddy, Send Message)

Journal of miyagawa (1653)

Sunday September 09, 2007
11:52 AM

Web::Scraper hacks #2: Extract javascript and css content

[ #34398 ]
This is inspired by an email from Renée Bäcker asking how to get content inside javascript tag. Because Web::Scraper's 'TEXT' mapping calls as_text method of HTML::Element, it doesn't get the content inside script and style tag. Here's the code that works. It's kinda clumsy, and it'd be nice if there's much cleaner way to do this:

#!/usr/bin/perl
# extract Javascript code into 'code'
use strict;
use Web::Scraper;

my $s = scraper {
    process "script", code => sub {
        join '', $_->content_list;
    };
};

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.