Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578457]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found