'\nthis book has much more to say later about htmlcgi scriptsand the meaning of the http get request used in example - (along with postone of two way to format information sent to an http server)so we'll skip additional details here suffice it to saythoughthat we could use the http interfaces to write our own web browsers and build scripts that use websites as though they were subroutines by sending parameters to remote programs and parsing their resultswebsites can take on the role of simple in-process functions (albeitmuch more slowly and indirectlythe urllib package revisited the http client module we just met provides low-level control for http clients when dealing with items available on the webthoughit' often easier to code downloads with python' standard urllib request moduleintroduced in the ftp section earlier in this since this module is another way to talk httplet' expand on its interfaces here recall that given urlurllib request either downloads the requested object over the net to local file or gives us file-like object from which we can read the requested object' contents as resultthe script in example - does the same work as the http client script we just wrote but requires noticeably less code example - pp \internet\other\http-getfile-urllib py ""fetch file from an http (webserver over sockets via urlliburllib supports httpftpfilesand https via url address stringsfor httpthe url can name file or trigger remote cgi scriptsee also the urllib example in the ftp sectionand the cgi script invocation in later files can be fetched over the net with python in many ways that vary in code and server requirementsover socketsftphttpurlliband cgi outputscaveatshould run filename through urllib parse quote to escape properly unless hardcoded--see later ""import sys from urllib request import urlopen showlines tryservernamefilename sys argv[ :cmdline argsexceptservernamefilename 'learning-python com''/index htmlremoteaddr 'print(remoteaddrremotefile urlopen(remoteaddrremotedata remotefile readlines(remotefile close(for line in remotedata[:showlines]print(linecan name cgi script too returns input file object read data directly here bytes with embedded \ the urllib package revisited