Want to develop a web browser in python – let me get you started with a small working prototype.
This GUI interface done in Tkinter and uses the urllib module to get the url data.
As you can see, the browser can read the contents of a site from the server. It currently does not parse HTML – hence you see raw html code for the fetched web page.
The design is also far from satisfactory – but the idea is to let a beginner have fun getting started with the project – not to write a full fledged production browser.
The Code So far
1) Fetching Data from the URL (urlhandler.py)
import urllib class urlhandler: address = '' data = '' def __init__(self, url): self.address = url def openURL(self): self.data = urllib.urlopen(self.address) def getURLdata(self): return self.data.read() def closeURL(self): self.data.close()
2) The GUI for the Browser (gui.py)
from Tkinter import * import urlhandler def go(): text.delete(1.0, END) conn = urlhandler.urlhandler(entry.get()) conn.openURL() text.insert(INSERT, conn.getURLdata()) conn.closeURL() browserwindow = Tk() browserwindow.title('knowpapa browser') label = Label(browserwindow, text= 'url:') entry = Entry(browserwindow) button = Button(browserwindow, text='Go', command = go) text = Text(browserwindow) label.pack(side=TOP) entry.pack(side=TOP) button.pack(side=TOP) text.pack(side= TOP) browserwindow.mainloop()
Suggestions for Adding New features
You can possibly think of adding the following capabilities to the browser:
1) Fetch the URL content on a new thread of execution as the current code blocks the GUI loop while the browser fethces the content. This should be easy. Use the threading module from Python standard library.
2) HTML parsing – You can check out the standard python library for html parsing.
4) Add a Layout engine (look inside WebKit,Gecko, Presto)
5) Ability to Handle Forms
6) Ability to Handle Cookies – urllib2 again !
7) Strengthening Security
8) Manage authentication information for a series of requests- urllib2 again !
9) Managing proxies – urllib2 !
10) Improve the GUI to make it look like from this century (Tkinter ttk library).
Look at the menu for any proper browser(Firefox, IE, Opera or Google Chrome) for tons of ideas for new features that can be added.
Download Source Code
And here’s the source code.
To run the browser – run the gui.py script.
If you have any more ideas for development or suggestions to make – leave it as a comment.