''' Purpose: print contents of a user-indicated web page ''' # ALL MODULES and info sheet are available during the test! # I would still be familarrrr so that you don't strictly # depend on it because you can Ctrl-F butttt if you don't know # how to use it.... then you're not allowed to look at your # old files or anything so remember that :) # THE EXAM is a Short Answer on Paper! AND A coding portion # on the computer. Look at old tests under Testing! # One of the best ways to ace the test is to go through # as many tests as you can and familiarize yourself with # how we might ask questions and know how to problem solve # questions we give you :) # You are not allowed to use PyCharm for the short answer! # need help to get web data - so import the capability from urllib.request import urlopen # get url link of interest reply = input( "Enter url: " ) # clean up the reply link = reply.strip() # get a connection to stream the web resource of interest stream = urlopen( link ) # read stream to gets its encoded contents encoding = stream.read() # decode contents into plain text form text = encoding.decode( "UTF-8" ) # get the lines that make up the text text = text.strip() # Remove leading or trailing whitespace lines = text.split("\n") # Take raw text from webpage and split the # webpage into a list of lines # .split(x) splits on a parameter! print( "Lines=", lines ) # We split by "\n" (newline character) # to separate the text at each new line # When running the url in the console, put a space after the link and hit # enter! # print the lines one by one for line in lines: print( line )