O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - spell-checking live HTML pages

In this example, we'll update our HTML spell-checker so that we can check pages that are already being served, without requiring local access to the file system. To do this, we'll make use of the Python urllib2 module.

  1. We'll be using html_spelling.py file as our base here, so create a copy of it and name the file html_spelling-b.py.
  2. At the top of the file, update your import statements to include urllib2, and remove the fileinput module as we'll not take advantage of it in this example.
    import urllib2
    import enchant
    import optparse
    
  3. Now, we'll update our module-level main code and add an option to accept a URL on the command-line.
     if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option('-u', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required