How do I open an HTML file in Python -
i've tried various different ways open html file python code, each time '500 internal server error'.
here python script:
if (variable == "0, user , ip logged"): #conditional check if user's credentials accepted api page = urllib.urlopen("mainpage.html").read() print page #html file opened , read - not working!
here html file:
<html> <header><title>this title</title></header> <body> hello world </body> </html>
how python script display hello world page? tutor said should use open(), i'm not sure how.
first of need run web server server web pages :
here using sample bottle web framework
bottle_server.py
from bottle import route, run @route('/') def dashboard(): return '<b>this index page</b>' run(host='localhost', port=8080)
run script using
python bottle_server.py
now, server running on localhost on port 8080
here sample python script
client.py
import urllib print urllib.urlopen('http://localhost:8080/").read()
run client script using
python client.py
this produce output
<b>this index page</b>
Comments
Post a Comment