[Zope] how can I dynamically bring in external page

Hung Jung Lu hungjunglu@hotmail.com
Mon, 28 Feb 2000 08:08:20 PST


>What I want to do is have a page served by zope
>which is in fact on another non Zope server but

It all depends on whether how much you know (or
want to know) about Zope and Python.

A simple

<dtml-call "RESPONSE.redirect('http://www.yahoo.com')">

redirects your page to Yahoo page. This is a very
simple solution. This way you don't violate any
law.

The next simplest solution is to use HTML frames. You
display the foreign page in a frame. But you must be
obtaining data from a consenting third party or provide
disclosure statements or features to remove the frame.

The best thing to do is to use Python external methods,
where you can extract things from a foreign source and
even strip things that you don't want. (I don't know
whether DTML has any method to do this directly. But
using Python external methods allows you much more
flexibility, because you can filter the fetched data
dynamically, using functions from the string or the
regular expression modules.) If you don't know how to
use external methods in Zope, you'll have to learn it
first.

--------------------------------------

import httplib

def gethtml(self, addr, page):
   h = httplib.HTTP(addr)
   h.putrequest('GET', page)
   h.putheader('Accept', 'text/html')
   h.endheaders()
   errcode, errmsg, headers = h.getreply()
   print errcode # Should be 200
   f = h.getfile()
   data = f.read() # Get the raw HTML
   f.close()
   # perform here whatever string operation
   # you need to do on data...
   return data

---------------------------------

After the external method has been implemented, you
you can call it by using:

<dtml-var "gethtml('www.yahoo.com', '/index.html')">

Hung Jung

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com