Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Counting links in a file?

by Amoe (Friar)
on Mar 24, 2002 at 19:47 UTC ( #153928=note: print w/ replies, xml ) Need Help??


in reply to Counting links in a file?

If it's only a really short hack, and the page doesn't contain the strings "http://" or "ftp://" outside of anchor tags, that'll be fine. For a slightly more sophisticated method, you can use the old mainstay HTML::TokeParser.

use HTML::TokeParser; my $count = 0; my $parsee = HTML::TokeParser->new('test.html') or die "couldn't open test.html: $!"; while (my $tag = $parsee->get_tag('a')) { $count++ if $tag->[1]{href} =~ m{(http|ftp)://}i; } print "There are $count links in this file.\n";

And if you ever want to do anything more complicated, which you probably will eventually, you have crazyinsomniac's superb tutorial to guide you.


--
my one true love


Comment on Re: Counting links in a file?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2015-08-01 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls