[Tutor] RE: Question on open and read html files and psycopg

Lee Harr missive at hotmail.com
Tue Sep 14 22:28:56 CEST 2004

>I have a question regarding python script opening and reading HTML files. 
>Can python
>read a html file containing frames? Because when I include this portion in 
>my script:

well... a file is  file. Python does not really care what is in the file.

Have you ever made a frame-based website just using html? As far as
I know, the frameset needs to be in a separate file from each of
the framed pages.

>fp=open("/var/www/cgi-bin/sf/frame.html", "r")
>     listOfLines= fp.readlines()
>     for eachline in listOfLines:
>         print eachline.strip()
>     fp.close()
>This is the frame.html:
><title>T4 Web Browser</title></head>
><frameset rows="80,*" BORDER=0>
><frame name="banner" scrolling="no" noresize target="contents" 
>src="title_bar.html"> <frameset cols="150,*" border=1>

So, here, the browser is now going to try to fetch a completely separate
file called title_bar.html and stuff its contents in to this frame.

><frame name="contents" target="main" src="side_bar.html" scrolling="auto">
><frame name="main" src="trial1.html" scrolling="auto">

Same thing with each of these frames...

><noframes><p>Hi, the page you are attempting to enter has frames and if 
>you're reading this message, you don't have the ability to see it. In order 
>to view this  page, you will need to update your browser.&nbsp;<p>Updates 
>are available from
><a href="http://www.microsoft.com/">www.microsoft.com</a> for Internet 
>Explorer or <a href="http://www.netscape.com/">www.netscape.com</a> for 
>Netscape Navigator.
>what the web browser returned is a web page containing the frames that I 
>have set up
>but not the contents of them. The frame.html consists of three more html 
>files - title_bar.html, side_bar.html and trial1.html. That is trial1.py is 
>capable of opening
>up and reading the frame.html file and display the frames but can't read 
>the rest. Thus, when i changed the frame.html to any of the html files, 
>trial1.py runs perfectly.
>I just wonder if anyone can tell me whether I'm right that python can't 
>read html files
>within another html file. (I hope someone get what I said);O
>Or please explain to me why does this happened? Thanks for any help.

I don' t think the problem is that python cannot read the files, but
you need to make sure that when the browser requests (for example)
side_bar.html that the response it gets is the contents of side_bar.html
and nothing else. The easiest way to do that may be to keep it as a
completely separate file.

>One more question on psycopg
>Finally, my machine is installed with psycopg and I'm wanna to try out it. 
>I'm a newbie so I find it difficult to write a program that is capable of 
>querying the database and display the result via a web browser whenever a 
>user do a keyword search.
>I have a postgreSQL DB up and running, my problem is with the code. Are 
>there anyone that is willing to share his/her source code that does similar 
>stuffs as mine do?
>Any help will be greatly appreciate. Thank you.

Your code worked perfectly well for me once I set it up for psycopg.
It looked to me like it was written for pypgsql.

Have you tried the psycopg examples? Those should get you started....

I do not have the code that I based on yours right here... I will try to
find it later today.

MSN 8 with e-mail virus protection service: 2 months FREE* 

More information about the Tutor mailing list