As a source of headlines you will be using http://www.cse.yorku.ca/course/1710/labs/GoogleNews.html, which is a local copy of the WWW page http://news.google.com. The text subsitutions should swap two random words in the headline.
For this, you have to write a function createNews() that has no arguments Each time it is called, it should automatically get the news headlines and (over-)write the output file, which has to be located at: "Z:\news.html".
The format of the output should be a normal HTML page, with an appropriate header. Each headline should be written as a level-1 heading, according to the HTML specification, i.e. using the '<h1>' tag. Do not forget to finish the generated HTML page with appropriate HTML sequences.
You must name your program lab10.py.
As a starting point, you can use the following code segment, which downloads the contents of a specified WWW page into a string.
import urllib contents = urllib.urlopen('http://www.cbc.ca') text = contents.read() contents.close() print textHere are a couple of hints:
<h2 class="title"> <a target="_self" class="irrelevant stuff" href="some link">Maple Leafs finally call it quits</a> </h2>Hence, you have to start by searching for each instance of '<h2 class="title">', then skip over the following link tag (e.g. by searching for the closing '>'), then extract all text after that until the start of the following tag.
Note that the text above has been broken into two lines to make it easier to understand. However, you can safely assume that the headline itself will not have a newline character inside it (but one of the tags may have a newline embedded).
submit 1710 lab10 lab10.py
Note: You must do all the above steps correctly for receiving full credit for this labtest.