On Sun, Apr 12, 2009 at 10:21 AM, Sander Sweers <sander.swe...@gmail.com> wrote: > 2009/4/10 Kent Johnson <ken...@tds.net>: >> Or, catch >> the exception, have the code find out where the error is and display >> the bad line. > > This is what I was looking for. I know how to catch the exception but > how do I make it display the bad line?
You had: tsoup = BeautifulSoup(readPage('http://url.sanitized')) and you got HTMLParseError: malformed start tag, at line 167, column 73 so try something like this (assuming Python 2.x): from HTMLParser import HTMLParseError data = readPage('http://url.sanitized') try: tsoup = BeautifulSoup(data) except HTMLParseError, ex: lines = data.splitlines() bad_line = lines[ex.lineno] print ex print repr(bad_line) # use repr() so non-printing chars will show Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor