''' Purpose: introduce web data acquisition -- print contents of word-of-the-day.txt from http://www.cs.virginia.edu/~cs1112/datasets/words/ ''' # need help to get web data - so import the capability import urllib.request # IMPORTANT CONSTANTS CS1112_WORDS_WEB_FOLDER = "http://www.cs.virginia.edu/~cs1112/datasets/words/" FILE_NAME = "word-of-the-day" # get a link to file of interest link = CS1112_WORDS_WEB_FOLDER + FILE_NAME #gives us a complete link to use #we're combining two strings into one long useable string # get a connection to stream the web resource of interest stream = urllib.request.urlopen( link ) #because of line 7, we can do this print ('stream =', stream ) #useless to us #we're using urlopen to connect pycharm to the link # read stream to gets its encoded contents page = stream.read() print('page =', page ) # decode page into plain text form text = page.decode() #we need to clean it into text humans can read easily # clean up text to get the word word = text.strip() # print word of the day print( word )