Component for stripping HTML?
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
HatForCat · 2017-04-21 16:07
Subject says it all.
I just need to strip all the HTML from incoming data. Mostly incoming
data it is all in plain text, but sometimes I get an HTML page. I have
no control over what is coming in, so I'd just like to strip out all
the HTML and just see the text parts.
Short of including the "HtmlViewer-11.7" from GitHub, I have not yet
found anything. I installed that HtmlViewer but it is too complicated
for my simple needs. I do not want to spend a few days figuring it out
just so I can strip out the HTML.
Helpful thoughts?
Thanks
----------------------------------------------------------------------
Bart · 2017-04-21 16:12
Simple approach: accept data until '<', drop data until '>'. Repeat
until end of data.
You'll end up with plain text.
You could also use fasthtmlparser (it comes with fpc) to parse the
text and use OnTag and OnText events to filter at will.
Bart
----------------------------------------------------------------------
wp · 2017-04-21 16:13
The fasthtmlparser from fpc packages\chm\src will do the job. Write a
handler for its OnFoundText which fires whenever a text node is found
within the html tree.
I once posted sample code for your task here, use the forum search
----------------------------------------------------------------------
HatForCat · 2017-04-21 22:23
Thanks, but I am also getting some other stuff in some of HTML data.
It is showing C++ style Remarks etc. Probably F# or worse.
I have had to mess with the HtmlViewer from GitHub.
----------------------------------------------------------------------
wp · 2017-04-21 22:26
Can you zip one of these html files and upload it here to have a look?
----------------------------------------------------------------------
mgear · 2017-04-25 23:50
I do the alike task now. Now it's written on Perl with DOM/CSS parser
Mojo::DOM. It works great but I need the embedded browser with
automated interaction and so am moving to Pascal. There's the mighty
DOM/XPath/XQuery/CSS parser there. Haven't tried it yet but it looks
very promising.
Internet Tools been found here
For example:
QuoteAt the lowest level you find the parseHTML function of the unit
simplehtmlparser.
It just splits a html document into tags and text elements and calls a
callback function for each of the elements.