pythontwill

Elegantly suppress Twill output in Python


I've recently been playing around with Twill and BeautifulSoup to do some basic screenscraping. However, it appears that one of the commands I'm using is printing a bunch of undesired output to the screen. Here's a quick snippet of the code I use to login to the site in question:

from twill.commands import *
from twill import get_browser

mybrowser = get_browser()
mybrowser.go(url)
mybrowser.showforms()
formvalue('1', 'email', email)
formvalue('1', 'password', password)
mybrowser.submit()
result = show()


At the moment, I'm using the "redirect_output()" function to pipe the undesired output to a garbage-filled text file...but this seems like a very hackish solution. Is there a more elegant way to avoid excessive printing with the commands above?


Solution

  • My best idea is:

    import os
    f = open(os.devnull,"w")
    twill.set_output(f)