Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-08

Fast HTML Parser

18 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas

Hi,

Someone knows a fast html parser to use in Pascal code?

I need something like this:

HTML:
<select name="sel_x">
<option>1</option>
<option>2</option>
</select>

I need a function/object to give me only the values: 1
2

Something like:
S := GetHTMLValues('sel_x');

Regards,
Marcos Douglas

Rainer Stratmann
to Marcos Douglas

It's not that difficult to write yourself.

you wrote 24 lines
Hi, Someone knows a fast html parser to use in Pascal code? I need something like this: HTML: <select name="sel_x"> <option>1</option> <option>2</option> </select> I need a function/object to give me only the values: 1 2 Something like: S := GetHTMLValues('sel_x'); Regards, Marcos Douglas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Marcos Douglas
to Rainer Stratmann
Rainer Stratmann wrote 21 lines
On Wednesday 06 August 2014 19:50:44 you wrote: > Hi, > > Someone knows a fast html parser to use in Pascal code? > > I need something like this: > > HTML: > <select name="sel_x"> > <option>1</option> > <option>2</option> > </select> > > I need a function/object to give me only the values: > 1 > 2 > > Something like: > S := GetHTMLValues('sel_x'); It's not that difficult to write yourself.

You're right. But I'm searching the faster HTML parser to use in huge HTML files... thousands of files.

Best regards,
Marcos Douglas

Mark Morgan Lloyd
to Marcos Douglas
Marcos Douglas wrote 25 lines
On Wed, Aug 6, 2014 at 2:54 PM, Rainer Stratmann wrote: > On Wednesday 06 August 2014 19:50:44 you wrote: >> Hi, >> >> Someone knows a fast html parser to use in Pascal code? >> >> I need something like this: >> >> HTML: >> <select name="sel_x"> >> <option>1</option> >> <option>2</option> >> </select> >> >> I need a function/object to give me only the values: >> 1 >> 2 >> >> Something like: >> S := GetHTMLValues('sel_x'); > It's not that difficult to write yourself. You're right. But I'm searching the faster HTML parser to use in huge HTML files... thousands of files.

I disagree: it's damn difficult if one isn't working with tightly constrained input, and the original question says HTML without specifying it's a subset.

There's a couple of places where I parse HTML files that I've created myself, i.e. I know exactly what's in them, using- basically- a simple recursive-descent parser with some rather flexible ideas about comments (i.e. in the above example, name="sel_x" could be lost as a comment). However if I'm doing a brute-force job over a large number of files I usually use Lynx as a preprocessor, which allows me to use standard text-processing utilities to pull named rows out of tabulated reports.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Marcos Douglas
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 44 lines
Marcos Douglas wrote: > > On Wed, Aug 6, 2014 at 2:54 PM, Rainer Stratmann > wrote: >> >> On Wednesday 06 August 2014 19:50:44 you wrote: >>> >>> Hi, >>> >>> Someone knows a fast html parser to use in Pascal code? >>> >>> I need something like this: >>> >>> HTML: >>> <select name="sel_x"> >>> <option>1</option> >>> <option>2</option> >>> </select> >>> >>> I need a function/object to give me only the values: >>> 1 >>> 2 >>> >>> Something like: >>> S := GetHTMLValues('sel_x'); >> >> It's not that difficult to write yourself. > > > You're right. But I'm searching the faster HTML parser to use in huge > HTML files... thousands of files. I disagree: it's damn difficult if one isn't working with tightly constrained input, and the original question says HTML without specifying it's a subset. There's a couple of places where I parse HTML files that I've created myself, i.e. I know exactly what's in them, using- basically- a simple recursive-descent parser with some rather flexible ideas about comments (i.e. in the above example, name="sel_x" could be lost as a comment). However if I'm doing a brute-force job over a large number of files I usually use Lynx as a preprocessor, which allows me to use standard text-processing utilities to pull named rows out of tabulated reports.

I know the tokens to search, but the HTML could be very different each other. I can't use a external tool. Need to be a application (that already exists).

Thanks,
Marcos Douglas

Graeme Geldenhuys
to Marcos Douglas
Marcos Douglas wrote
I know the tokens to search, but the HTML could be very different each other. I can't use a external tool. Need to be a application (that already exists).

Take a look at POWtils (aka PWU or PSP or Pascal Server Pages) created by somebody known as Z505. There has been various locations for the source code, but I think the latest is at:

https://code.google.com/p/powtils/

It has (or at least had) a very simple to use HTML parser that was very fast. If you don't come write with the above URL, I have some release archives I know contains the code. Just let me know and I can make it available.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Graeme Geldenhuys
to Marcos Douglas: On Wed, Aug 6, 2014 at 5:46 PM, Mark Morgan Lloyd I know the tokens to search, but the…
Marcos Douglas wrote
I know the tokens to search, but the HTML could be very different each other. I can't use a external tool. Need to be a application (that already exists).

It seems a copy of the Fast HTML Parser unit I spoke of has made its way into the FPC source code tree.

See <fpc_src>/packages/chm/src/fasthtmlparser.pas

Attached is the original one I got from powtils release. It includes the parser, a utility unit and a demo program showing the parser in action with some stats output.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Andrew Haines
to Marcos Douglas: Someone knows a fast html parser to use in Pascal code? I need something like this: HTML:…
Marcos Douglas wrote 20 lines
Hi, Someone knows a fast html parser to use in Pascal code? I need something like this: HTML: <select name="sel_x"> <option>1</option> <option>2</option> </select> I need a function/object to give me only the values: 1 2 Something like: S := GetHTMLValues('sel_x'); R

There is the unit fasthtmlparser included with fpc in the packages/chm folder.

It is pretty basic and just has callbacks for tags and text. I don't think it's smart enough to tell you of the

name="sel_x" part of your tag. Maybe it can be improved.

Regards,

Andrew Haines

Marcos Douglas
to Andrew Haines
Andrew Haines wrote 29 lines
On 08/06/14 13:50, Marcos Douglas wrote: > Hi, > > Someone knows a fast html parser to use in Pascal code? > > I need something like this: > > HTML: > <select name="sel_x"> > <option>1</option> > <option>2</option> > </select> > > I need a function/object to give me only the values: > 1 > 2 > > Something like: > S := GetHTMLValues('sel_x'); > > R There is the unit fasthtmlparser included with fpc in the packages/chm folder. It is pretty basic and just has callbacks for tags and text. I don't think it's smart enough to tell you of the name="sel_x" part of your tag.

You're right, but I change my code to use fasthtmlparser and worked (at least for now). Thank you.

Maybe it can be improved.

I agree. If I change something, I'll send a patch.

Marcos Douglas

Michael Schnell
to Rainer Stratmann: It's not that difficult to write yourself.
Rainer Stratmann wrote
It's not that difficult to write yourself.

In fact, my son once did write (using Delphi) a parser that creates a list of hierarchically linked objects from HTML code and also can write a HTML file from this structure.

So you can read a file, use straight forward programming to modify the content, and write it back.

As the HTML format is not very strict and is a moving target, the parser unit is far from perfect, but it is in daily use and does a rather nice job.

OTOH, I would not say it's fast, anyway :-( .

-Michael

Marcos Douglas
to Graeme Geldenhuys: Take a look at POWtils (aka PWU or PSP or Pascal Server Pages) created by somebody known…
Graeme Geldenhuys wrote 14 lines
On 2014-08-06 21:54, Marcos Douglas wrote: > I know the tokens to search, but the HTML could be very different each other. > I can't use a external tool. Need to be a application (that already exists). Take a look at POWtils (aka PWU or PSP or Pascal Server Pages) created by somebody known as Z505. There has been various locations for the source code, but I think the latest is at: https://code.google.com/p/powtils/ It has (or at least had) a very simple to use HTML parser that was very fast. If you don't come write with the above URL, I have some release archives I know contains the code. Just let me know and I can make it available.

But the fasthtmlparser, your tip before, is a powtils' source, don't? I have the code -- for many years -- but I did not know about fasthtmlparser. It's very simple. I did not found everything I want but it is a good start.

Best regards,
Marcos Douglas

PS: Like you I use FPC in real applications in production. So I have a deadline - always short - to fulfill. So finding good code to help in our projects is very good because it makes us save time. Thanks.

Marco van de Voort
to Marcos Douglas

In our previous episode, Marcos Douglas said:

Show quoted text 9 lines
> It has (or at least had) a very simple to use HTML parser that was very > fast. If you don't come write with the above URL, I have some release > archives I know contains the code. Just let me know and I can make it > available. But the fasthtmlparser, your tip before, is a powtils' source, don't? I have the code -- for many years -- but I did not know about fasthtmlparser. It's very simple. I did not found everything I want but it is a good start.

Yes it is. The CHM parser is also based on it, but there z505 is not listed as author but as contributor:

AUTHOR : James Azarja
http://www.jazarsoft.com/

CONTRIBUTORS : L505
http://z505.com

luiz americo pereira camara
to Marco van de Voort

You can try http://www.benibela.de/sources_en.html#internettools

Luiz

2014-08-07 10:20 GMT-03:00 Marco van de Voort :

Show quoted text 25 lines
In our previous episode, Marcos Douglas said: > > It has (or at least had) a very simple to use HTML parser that was very > > fast. If you don't come write with the above URL, I have some release > > archives I know contains the code. Just let me know and I can make it > > available. > > But the fasthtmlparser, your tip before, is a powtils' source, don't? > I have the code -- for many years -- but I did not know about > fasthtmlparser. It's very simple. I did not found everything I want > but it is a good start. Yes it is. The CHM parser is also based on it, but there z505 is not listed as author but as contributor: AUTHOR : James Azarja http://www.jazarsoft.com/ CONTRIBUTORS : L505 http://z505.com _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal