Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

mirod's scratchpad

by mirod (Canon)
on Jun 02, 2004 at 01:56 UTC ( #358990=scratchpad: print w/replies, xml ) Need Help??

#!/usr/bin/perl -w use strict; use LWP; use Getopt::Std; use XML::Twig; use Getopt::Std; my %opt; getopts( 'kf:' => \%opt); my $params= { node_id => 3989, n0 => 220215, BIT => 'use XML::Twig;', # text to search for BIS => '-', # string separator BH => 1, # match in title too HIT => "", HIR => 0, # ?? a => 'mirod', # just one author xa => 0, # exclude author xs => 0, # exclude section BES => '-', HER => 0, # ?? xr => 0, # exclude root nodes re => 'S', # ?? go => 'Search', #displaytype => 'xml', }; my $URL= ""; my $doc; if( my $file= $opt{f}) { open( IN, "<$file") or die $!; local $/= undef; $doc=<IN>; close IN; } else { my $browser= LWP::UserAgent->new(); my $resp= $browser->post( $URL, $params); $doc= $resp->content; } my $TMP= "$0.tmp"; open( TMP, ">$TMP") or die $!; print TMP $doc; close TMP; system "tidy -asxhtml -numeric -modify $TMP"; my $t= XML::Twig->new( keep_encoding => 1); $t->parsefile( $TMP); my $content= $t->first_elt( '[@class="main_content"]'); my $table= $content->first_child( 'table'); my $data; foreach my $tr ($table->children( 'tr')) { my @td= $tr->children( 'td'); $td[1]->cut; $td[3]->cut; my $a= $td[2]->first_child( 'a'); my $href= $a->att( 'href'); $href="$href"; $a->set_att( href => $href); } $table->sort_children_on_field( 'td', order => 'reverse'); $table->print; warn "done\n"; if( $opt{k}) { warn "raw data is in $TMP\n"; } else { unlink $TMP; }
Log In?

What's my password?
Create A New User
[marioroy]: Back in HighSchool, I came late to Gym class. There was a fellow who was picked last, no team wanted him for racketball. So it was us two against everybody. I looked at him in the eye and said to let your body loose and let the powers to be help us win.
[marioroy]: We made it all the way to the end. The expience was magical. I not good at sports. Someone or thing was there.
erix considers extracting a catalog ...
[karlgoethebier]: marioroy: Racket ball is considered harmful, like Squash
[marioroy]: Wait till folks see what MCE::Hobo can do in the upcoming release. Multiple instances, nested spawning, 3 levels, doesn't matter. it works on Windiows too.
[Lady_Aleena]: I hate sites that tell me to turn ad-blocker off. They should know better.
[marioroy]: s/Windiows/ Windows/
[Discipulus]: marioroy can you expand that Niagara's fall history?
erix only sees fallen angels
erix if it weren't for bad luck, I'd have no luck at all

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-05-29 08:46 GMT
Find Nodes?
    Voting Booth?