Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: problem parsing html

by spx2 (Deacon)
on Jul 16, 2009 at 09:00 UTC ( [id://780608]=note: print w/replies, xml ) Need Help??


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

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;

Replies are listed 'Best First'.
SOLVED: problem parsing html
by paola82 (Sexton) on Jul 16, 2009 at 10:10 UTC

    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://780608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found