''' Purpose: introducing the acquisition of web data -- determine the hidden super power of a CS 1112 person ''' # to help understand these commands go to the urllib.request module on the website # need help to get web data - so import some capabilities import urllib.request # define the base folder for course participants BASE_PEOPLE_URL = 'http://www.cs.virginia.edu/~cs1112/people/' # get computing id of interest reply = input( 'Enter computing id: ' ) #id = reply.strip().lower() # This is the pythonic way of doing it. It will work id = reply.strip() # order does not matter id = id.lower() # specify web folder of indicated person person_folder = BASE_PEOPLE_URL + id + '/' #a slash means we are talking about a folder # specify link for super power web file of indicated person power_file = person_folder + 'super-power.txt' #print ( power_file ) # get a connection to the web resource of interest stream = urllib.request.urlopen( power_file ) #print( stream ) # read stream to get its contents page = stream.read() #print( page ) # decode contents into plain text form text = page.decode( 'UTF-8' ) # unicode the standard US version; you will always use this # text is the superpower of interest print( text )