Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 9th, 2005, 11:31 AM   #1
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Parsing a piece of HTML

Yo all! ^_^

I've got a web page that dynamically creates a tree-like directory structure with given input by the user. It would be in a form like the following:

...

<ul id="root">
   <ul>
      <li> 
         Dir1 <button onclick='add()'>Add another</button>
      </li>
   </ul>
   <ul>
      <li>
         Dir2 <button onclick='add()'>Add another</button>
      </li>
      <ul>
         <li>
            file_in_dir2 <button onclick='add()'>Add another</button>
         </li>
       </ul>
    </ul> 
</ul>

...

(Sure hope the spacing worked out ok) The overkill on the <ul> elements is so that the dir will have a tree-like structure when it is rendered in the browser. Anyhow, I need to generate an xml document from the information on the form. The things that are in the data fields are trivial, (at least they should be) but this data structrue is giving me some greef.

How exactly do I pass this onto python to parse and save in the xml file? Any thoughts?

Thanks! ^_^
MegaArcon is offline   Reply With Quote
Old Dec 9th, 2005, 1:31 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
You might want to look at Beautiful Soup
Arevos is offline   Reply With Quote
Old Dec 12th, 2005, 7:37 AM   #3
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Looks interesting. I'll see if I can use that to figure it out. However, it seems that all the examples that are there only pass in html files. I'm still at a loss as to how to pass dynamic content off to python.
MegaArcon is offline   Reply With Quote
Old Dec 12th, 2005, 9:54 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by MegaArcon
Looks interesting. I'll see if I can use that to figure it out. However, it seems that all the examples that are there only pass in html files. I'm still at a loss as to how to pass dynamic content off to python.
What do you mean? So long as it's HTML you're parsing, it does not matter where you get the HTML from, be it a .html file on your computer, or from a dynamically generated web page through HTTP.
Arevos is offline   Reply With Quote
Old Dec 12th, 2005, 10:45 AM   #5
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Sorry for being unclear. The problem I was having was exactly HOW to get the dynamcially generated string of html off the page. I made a quick trip over to the javascript section, and I can get access to it by:

document.getElementsByTagName("html")[0].innerHTML

Or something along those lines. ^_^

Thanks all! I'll play around with this and it should (by the looks of it) solve my problem.
MegaArcon is offline   Reply With Quote
Old Dec 12th, 2005, 12:42 PM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Oh! You mean dynamically created by javascript, rather than a server-side language like PHP?
Arevos is offline   Reply With Quote
Old Dec 12th, 2005, 4:08 PM   #7
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Bear in mind that though innerHTML is supported by all recent modern graphical browsers it isn't part of the W3 standard - by all means use it, just know who your target audience. With that said you're using other JavaScript stuff for dynamically adding form elements, so you should be okay really.
Cerulean is offline   Reply With Quote
Old Dec 13th, 2005, 7:50 AM   #8
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
Yea, I was building this with the standars in mind, but IE made my scripts cry. I'm doing some kinda trickey stuff with this project, and unfortunatly, some anti-standard stuff had to be used to get the blasted thing to work....o.k, I guess that's a lie. I'm sure there was a way (or two or three) to get around my problems and keep to standards...but oh well. At least most of the firefox/mozilla parts are by the standard.

And I do, fortunatlly, know my audience and I'm testing it on the browsers that they use. (Aside from Konqueror....poor Konqueror)
MegaArcon is offline   Reply With Quote
Old Dec 14th, 2005, 11:45 AM   #9
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Most Firefox script thingys worth with our beloved Konqueror, so you should be alright. As long as you don't use too many exotic things you should be okay - Konqueror has wonderful support for innerHTML, XmlHTTPRequest, and so on.
Cerulean is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC