473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parsing html chunks

I have been trying to figure out the best way to parse some chunks of html code that contain tables. I've been trying to do this with HTML::Parser and HTML::TokeParser and HTML::TokeParser::Simple, but I just can't seem to get everything working the way I want. The chunks are from a standard template so there is some structure to the data, but it is not that simple.

The problem:
There can be bare text before, after or between each table in the chunk.
There can be embedded tables (tables within tables)
There can be multiple tables in series. (one after the other)
There can be embedded tables and tables in series in the same chunk.

If you've ever looked at a PHPBB forum, the chunks I am working with are the posts. The tables are quoted text within those posts. I need to remove the HTML code and replace it with the BBCode used by the forum so it can then be put into the database. I know PHPBB uses a database backend, but I do not and cannot get access to it.

What I am trying to accomplish is to pull the text out of the table and then eventually insert it into the database. Where I'm having problems is storing the text in a variable so that it can be recreated in the order in which it would look on the html page in a browser.

With HTML::Parser I was able to get a single table of data out, but when I started getting into the multiple levels of tables, I didn't really have a clean way to hold on to what I had already parsed while I continued through the chunk.

With HTML::TokeParser::Simple I was able to do the same thing, but I end up in a sea of flags trying to capture the right data at the right time. If I had a way with this module to extract the contents of the entire table structure and then parse that one thing at a time, I think I'd be all set. I seem to be able get close to the solution with both modules coming at the problem from two different directions, but can't quite get the entire solution.

Can anyone provide any insight into what I might possibly try or consider in order to get this project finished? I'm not asking for help with the coding per se, just a useful design method to solve this problem. I'm not a perl expert by any means, but I can make my way through the docs and some books to figure most things out.
Apr 2 '08 #1
3 2440
numberwhun
3,509 Expert Mod 2GB
The HTML::Parser module is probably your best bet. Take a look at this tutorial and see if it helps.

Regards,

Jeff
Apr 5 '08 #2
KevinADC
4,059 Expert 2GB
There is a module specifically for parsing html tables, HTML::TableParser, but I have never used it so can't help with the interface.
Apr 5 '08 #3
Thanks for the pointers. I appreciate the help. The HTML::TableParser looks really good. I hadn't found that one. One thing I did do was to look back at my problem objectively and see why I couldn't do what I needed to. What I found was I was spending too much time looking at the output of the data and not the data itself. I think I found the most effective way for me to parse through the data and use a set of flags to capture the right data at the right time. Its working so I'll continue going with it. I did end up using HTML::TokeParser::Simple.

The problem I had with HTML::Parser was not being able to use a variable to store the text I wanted to save without creating a subclass. I'm not super knowledgeable on perl so I had a hard time figuring out how to do what I wanted with it. I use that for another piece of the same project and it worked perfect for that.

Thanks again for your suggestions.
Apr 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Kylotan | last post by:
I have a text file where the fields are delimited in various different ways. For example, strings are terminated with a tilde, numbers are terminated with whitespace, and some identifiers are...
3
by: anon | last post by:
So I've encountered a strange behavior that I'm hoping someone can fill me in on. i've written a simple handler that works with one small exception, when the parser encounters a line with '&' in...
3
by: Girish | last post by:
Hi All, I have written a component(ATL COM) that wraps Xerces C++ parser. I am firing necessary events for each of the notifications that I have handled for the Content and Error handler. The...
1
by: Girish | last post by:
Hello.. I need to understand how parsing of a file or a stream(XML data in memory) takes place in Xerces C++. I am using SAX XMLReader and passing xml input as a file path or a MemBufInputSource...
6
by: ArunPrakash | last post by:
Hi, I have a web application that looks for a particular string in a set of huge files( the files grow into MBs - max i have seen is 30 MB ). ( search using reg expressions ). the string can occur...
9
by: Hemang Shah | last post by:
Hello fellow Coders! ok, I"m trying to write a very simple application in C#. (Yes its my first program) What I want to do is : 1) Open a binary file 2) Search this file for a particular...
1
by: Kenneth McDonald | last post by:
I'm writing a program that will parse HTML and (mostly) convert it to MediaWiki format. The two Python modules I'm aware of to do this are HTMLParser and htmllib. However, I'm currently...
22
by: Spartanicus | last post by:
I wrote an article on HTML headings: http://codewallop.110mb.com/goodpractice/headingology.htm -- Spartanicus
4
by: egonslokar | last post by:
Hello Python Community, It'd be great if someone could provide guidance or sample code for accomplishing the following: I have a single unicode file that has descriptions of hundreds of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.