[Zope] Accessing DOM nodes from python: how?

Catonano a.peluso@fulltrading.it
Sat, 22 Dec 2001 11:49:30 +0100


Tom,

On Fri, 20 Dec 2002 16:40:06 -0500, Passin, Tom wrote:
> [ Catonano]
> 
>>  I saw a javascript accessing a value put in a html tag like this:
>>  
>>  
>>  <TD ID= "blah">
>>  Td contents
>>  </TD>
>>  
>>  or something similar.
>>  
>>  Javavascript could read that "blah"
>>  
>>  Now, how can I do the same from python? Can I?
>>  
> 
> I am not at all sure what you want to do. 
> When the javascript script
> accesses that value, it is operating in the browser.  Python will be in
> the server.  Why should it access the page at all?  If there is data to
> be sent to Python, just send it the data.  The page, in fact, will not
> actually exist for Python to "access".  Only after your python scripts
> are done will the page be fully assembled.
> 
> If you mean that you want to write some python code that you feed an
> html page to, that is not how you would normally use Zope.  


thanks for your suggestions.

On my side I'm not so sure about what I want to do, I try to explain:

We have a folder with a bunch of html files in it.

What I want to do is to make a drop down menu filled with some values.

Each one of these values individuates one of the files in the folder.

If I, as user, choose a code from the drop down menu, it should take me 
to the associated file (web page, that is).

The files are not dinamically produced by Zope, they are simple 
statical html files made by some collagues of mine with DreamWeaver and 
uploaded via ftp into my folder.

I could ask my collagues to include the code in every page (file) in a 
html-compliant shape, so Zope could acces that code and CATALOGUE those 
pages indexing that code, so I could try with a multiple choiche menu.

Is it clearer?

My idea is that I have 2 alternative ways:

1)  add a field property to each file and fill it with the code, then 
adding an index to my ZCatalog. Boring, error prone and time consuming.

2) ask my collagues to inclue the codes in the html files and get Zope 
access and index that values.

Am I missing some pieces?

You say:
 
> If you want Python to access a web page and retrieve some data from it
> while it is processing a REQUEST, that is best done using an external
> method.  There are a variety of ways to process a web page, but it is
> not always easy, given the amazing range of invalid html code that
> exists out there.

Well, I assume my collagues will provide me with correct html. 
Otherwise I can always ask them to fix it.

>  Sometimes it is easiest to use regular expressions,
> and sometimes it is easiest to use the sgmlop parser (you have to write
> a handler, but that is not too hard depending on what you need to do).  
> 
> Or you can turn the html page into xml using HTML Tidy, then use xml
> processing on the page.  If you do this and use the PyXML beta (or maybe
> it is still alpha) package, you can get access to the W3C DOM API, and
> access the page element content that way.
> 
> Cheers,
> 
> Tom P
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )