Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Any pure-perl html to text? (Or: missing a perl equivalent to 'lynx -dump')

by monarch (Priest)
on Oct 16, 2006 at 08:52 UTC ( #578457=note: print w/replies, xml ) Need Help??


in reply to Any pure-perl html to text? (Or: missing a perl equivalent to 'lynx -dump')

I tend to do these things by hand, even though I know I really shouldn't.
my $string = "..htmlstuff.."; # strip out newlines $string =~ s/[\r\n]+/ /sg; # replace <p> with custom paragraph marker my $marker_paragraph = "**PARAGRAPHHERE**"; $string =~ s/<p(\s[^>]*)?>/$marker_paragraph/isg; # remove all HTML tags $string =~ s/<[^>]*>//sg; # replace custom paragraph marker with blank line $string =~ s/\Q$marker_paragraph\E/\n\n/sg;

You can add other transforms, such as wrapping at a particular column etc.

  • Comment on Re: Any pure-perl html to text? (Or: missing a perl equivalent to 'lynx -dump')
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2020-10-31 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (287 votes). Check out past polls.

    Notices?