Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: problem parsing html

by paola82 (Sexton)
on Jul 16, 2009 at 08:37 UTC ( [id://780600]=note: print w/replies, xml ) Need Help??


in reply to Re: problem parsing html
in thread problem parsing html

thanks...you quite solved my problem..but I have the last question...:the script returned chains...but they are as a block...I need to ave A,B,C etc...as single element of the array...because I need to start a cycle for every chain...I try to search "split" the name make me remember something...that can be useful?

Replies are listed 'Best First'.
Re^3: problem parsing html
by spx2 (Deacon) on Jul 16, 2009 at 09:00 UTC
    As I understand , you only want unique chains , you can do this with minimum effort:
    1 #!/usr/local/bin/perl 2 use strict; 3 use warnings; 4 use LWP::Simple; 5 use HTML::TreeBuilder::XPath; 6 use Data::Dumper; 7 use feature 'say'; 8 my $url="http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdbsu +m/GetPage.pl?pdbcode=1r9t&template=main.html"; 9 10 my $p = HTML::TreeBuilder::XPath->new_from_content(get($url)); 11 12 my @chain_tags = $p->findnodes("//td//a[contains(\@href,'chain=')] +"); 13 my $uniq_chains = { map { $_->attr('href') =~ /chain=(\w)/; ($1,1) +; } @chain_tags }; 14 say " Number of chains : " . scalar keys %$uniq_chains; 15 say keys %$uniq_chains;

      I used your code and add the function split

      #!/usr/local/bin/perl use strict; use warnings; use LWP::Simple; use HTML::TreeBuilder::XPath; use Data::Dumper; my $url="http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdbsum/Ge +tPage.pl?pdbcode=1r9t&template=main.html"; my $p = HTML::TreeBuilder::XPath->new_from_content(get($url)); my @chain_tags = $p->findnodes("//td//a[contains(\@href,'chain=')]"); my @chains = map { $_->attr('href') =~ /chain=(\w)/ } @chain_tags; my @chain = map {split ' '} @chains; foreach my $chain (@chain){print "$chain\n";}

      the output was:

      pisolo@pisolo:~/Scrivania/test$ perl test7.pl A A B C E F H I J K L

      so I think I can iterate my analysis for every chain....using as array with foreach....Thanks.... :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found