reply close(for line in data[:showlines]print(linefile obj for data received show lines with eoln at end to savewrite data to file line already has \nbut bytes desired server names and filenames can be passed on the command line to override hardcoded defaults in the script you need to know something of the http protocol to make the most sense of this codebut it' fairly straightforward to decipher when run on the clientthis script makes an http object to connect to the serversends it get request along with acceptable reply typesand then reads the server' reply much like raw email message textthe http server' reply usually begins with set of descriptive header linesfollowed by the contents of the requested file the http object' getfile method gives us file object from which we can read the downloaded data let' fetch few files with this script like all python client-side scriptsthis one works on any machine with python and an internet connection (here it runs on windows clientassuming that all goes wellthe first few lines of the downloaded file are printedin more realistic applicationthe text we fetch would probably be saved to local fileparsed with python' html parser module (introduced in )and so on without argumentsthe script simply fetches the html index page at -python coma domain name host at commercial service providerc:\pp \internet\otherhttp-getfile py learning-python com /index html '\nb\nb'\nb"mark lutz' python training services\nb'<link rel="stylesheettype="text/csshref="_themes/blends/blen '\nnotice that in python the fetched data comes back as bytes strings againnot strsince the python html parser html parse we'll meet in expects str text strings instead of bytesyou'll likely need to resolve unicode encoding choice here in order to parsemuch the same as we did for email message text earlier in this as therewe might decode from bytes to str per defaultuser preferences or selectionsheaders inspectionor byte structure analysis because sockets send raw byteswe confront this choice point whenever data shipped over them is text in natureunless that text' type is known or always simple in formunicode implies extra steps we can also list server and file to be fetched on the command lineif we want to be more specific in the following codewe use the script to fetch files from two different websites by listing their names on the command lines ( 've truncated some of these lines so they fit in this booknotice that the filename argument can include an arbitrary remote directory path to the desired fileas in the last fetch herec:\pp \internet\otherhttp-getfile py www python org /index html www python org /index html '<!doctype html public "-// //dtd xhtml transitional//en"httpaccessing websites