''' Purpose: print contents of a user-indicated web page ''' # get url link of interest reply = input( "Enter url: " ) ############### BOILERPLATE TO GET CONTENTS OF WEB FILE ############### #we've seen all of this before # need help to get web data - so import the capability from urllib.request import urlopen # # # clean up the reply link = reply.strip() # # # get a connection to stream the web resource of interest # stream = urllib.request.urlopen( link ) # # # read stream to gets its encoded contents # page = stream.read() # # # decode page into plain text form # text = page.decode() #print( text ) ############### END OF BOILERPLATE ############### # the above code is tedious, need a function to do take care this crud import url #homemade module used to do all the streaming etc. for you #typing the same four lines gets annoying so this saves us time #please use this. It will save you time text = url.get_contents( link ) # now let's get the lines that make up the text print( 'text =' , text ) # split the text into a list of line lines = text.split( "\n" ) #we can tell .split() to split on anything we want, in this case we telling it to split on new lines # print the lines one by one print( "lines" ) for line in lines : print( "line =", line )