1. Computing & Technology

Building a Web Client in Python

From , former About.com Guide

Printing the Web Page With Python

Now, all of the data is contained within buff. All we need to do is step through it, printing as we go.

 for line in buff: print line 

Now, you can save the program and call it with the name of the server and the name of the file you want to see. For example, try:

python simple_web_client.py python.about.com /

If you run your own server, you can access your web directory as follows:

python simple_web_client.py localhost / What you will receive is the raw HTML of the index file. You can then process it as plain text or parse it with urllib or urllib2.

©2012 About.com. All rights reserved.

A part of The New York Times Company.