Coding Horror is usually a good read, sometimes it’s just way too long and I skip it, but there are a few posts that are memorable. The one from earlier this week called Parsing HTML the Cthulhu Way was spectacular.
Even Jon Skeet cannot parse HTML using regular expressions. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing HTML with regex summons tainted souls into the realm of the living. HTML and regex go together like love, marriage, and ritual infanticide. The <center> cannot hold it is too late. The force of regex and HTML together in the same conceptual space will destroy your mind like so much watery putty. If you parse HTML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes.
It just gets better from there. Which leads me back to my google reader inbox where Jay Huie shared a link to Parsing HTML in Python with BeautifulSoup. This reminded me of a little pet project of mine from a couple months ago. I had given up on it, due to parsing html formatted logs with regex. On monday after reading the coding horror article I dusted it off and was able to fix it up with beautiful soup within an hour.
All of this is a long way of saying don’t reinvent the wheel and if you need to work with HTML in python use BeautifulSoup.
Also all hail Cthulhu.