but soft what light through yonder window breaks it is the east and juliet is the sun arise fair sun and kill the envious moon who is already sick and pale with grief as an examplewe can write program to retrieve the data for romeo txt and compute the frequency of each word in the file as followsimport urllib requesturllib parseurllib error fhand urllib request urlopen('counts dict(for line in fhandwords line decode(split(for word in wordscounts[wordcounts get(word print(countscodeagainonce we have opened the web pagewe can read it like local file reading binary files using urllib sometimes you want to retrieve non-text (or binaryfile such as an image or video file the data in these files is generally not useful to print outbut you can easily make copy of url to local file on your hard disk using urllib the pattern is to open the url and use read to download the entire contents of the document into string variable (imgthen write that information to local file as followsimport urllib requesturllib parseurllib error img urllib request urlopen('fhand open('cover jpg''wb'fhand write(imgfhand close(codethis program reads all of the data in at once across the network and stores it in the variable img in the main memory of your computerthen opens the file cover jpg and writes the data out to your disk the wb argument for open(opens binary file for writing only this program will work if the size of the file is less than the size of the memory of your computer however if this is large audio or video filethis program may crash or at least run extremely slowly when your computer runs out of memory in order to avoid