#------------------------------------------------------------------------------ # Web.py #------------------------------------------------------------------------------ from urllib.request import urlopen def get_page(url): """ Retrieve the contents of a web page, convert it to a string, then return the string. """ socket = urlopen(url) # open a connection to url on the internet data = socket.read() # read entire page as a byte stream socket.close() # close connection s = str(data, 'utf-8') # convert bytes to string using utf-8 encoding return s # return string # end get_page() # main() ---------------------------------------------------------------------- def main(): text = get_page('https://classes.soe.ucsc.edu/cse020/Fall21/') print() print(text) print() # end main() ------------------------------------------------------------------ # ----------------------------------------------------------------------------- if __name__=='__main__': main() # end if ----------------------------------------------------------------------