Skip to main content

Section 13.17 Write Code Questions

Activity 13.17.1.

Complete the following code that retrieves the file ‘romeo.txt’ from. Make changes to line 4 and 5.
Solution.
Complete the following code that retrieves the file ‘romeo.txt’ from. Make changes to line 4 and 5.

Activity 13.17.2.

Complete the following code to extract an image ‘cover3.jpg’ from the URL ‘http://data.pr4e.org/cover3.jpg’ and host ‘data.pr4e.org’. There are 5 empty spaces.

Activity 13.17.3.

Complete the following code that retrieves the text from ‘http://data.pr4e.org/clown.txt’, prints it and also prints the frequency of each word.
Solution.
Complete the following code that retrieves the text from ‘http://data.pr4e.org/clown.txt’ and prints the frequency of each word.

Activity 13.17.5.

Write a program to store image file from ‘http://data.pr4e.org/cover.jpg’ to your disk.
Solution.
Write a program to store image file from ‘http://data.pr4e.org/cover.jpg’ to your disk.

Activity 13.17.6.

Complete the following program to extract all url from the webpage using regex.

Activity 13.17.7.

Write a program that retrives a txt file from ‘https://www.gutenberg.org/files/1342/1342-0.txt’ in several blocks of 100,000 characters, joins them and saves as ‘prideandprejudice.txt’ to disk and prints number of characters.
Solution.
Write a program that retrives a txt file from ‘https://www.gutenberg.org/files/1342/1342-0.txt’ in several blocks of 100,000 characters, joins them and saves as ‘prideandprejudice.txt’ to disk and prints number of characters.

Activity 13.17.8.

Write a program that retrives a txt file from ‘https://www.gutenberg.org/files/16/16-0.txt’ in several blocks of 100,000 characters, joins them and saves as ‘peterpan.txt’ to disk and prints number of characters.

Activity 13.17.9.

Complete the following code to print all the image sources from the webpage. Use ‘img’ and ‘src’ as tags.
Solution.
Complete the following code to print all the image sources from the webpage. Use ‘img’ and ‘src’ as tags.

Activity 13.17.10.

Write code that extracts data from several parts of the ‘a’ tag from “http://www.dr-chuck.com/page1.htm” using BeautifulSoup and html.parser and print the tag, href, contents as well as all the attributes.
You have attempted of activities on this page.