Did You Know: BeautifulSoup's bits are rotting
crummy.com
crummy.com
Does anyone else wonder why we're writing all these parsers when both Mozilla and WebKit have reliable, robust parsers that are actively maintained? How difficult would it be to package up the existing code and distribute it with wrappers for python, ruby, etc... I assume there's something I don't know, because not only has it not been done, but no one seems to want to talk about it.
I use a similar technique to get emacs to syntax-highlight my slides. Connect to the running emacs (with all my settings), run htmlify via emacsclient --eval, and enjoy perfect highlighting!
Either way, it is kind of inelegant, but it is hard to pick-and-choose parts of Mozilla. This is probably the simplest way to let Mozilla parse your HTML. (That, however, may not be necessary. I have done a lot of screen-scraping, and I have never encountered anything that HTML::TreeBuilder got confused on. Lately, I've been using libxml2, and that has also worked very well. Zero problems.)
It's really too bad that there's not enough money in it for Leonard to keep it up. But, I have no bitterness, just thanks!
"To make the time for Beautiful Soup development, I'd need enough money to make it my job, and that's too much money to ask for or to expect."
Money == Time
He's standing up to say he's going to honor his responsibility to this code even though he doesn't enjoy it anymore, but that that doesn't include writing html parsers, and you come along and scream 'bitrot'. Sorry, but that's kind of an assholish thing of you to do.
Personally, I can't/won't pitch in on BeautfulSoup, but I thought maybe if I posted the page to this forum, a better hacker than myself might jump in. We can across the behavior he describes in building TrailBehind, and I just thought I'd share with the community.
As for bit rot, that's a pretty old term that just means code breaks down as it ages.
Titles get changed here all the time, why couldn't this one be changed to just a simple statement of fact, something like: "Beautiful Soup switches parsers, developer requests help replacing lost functionality"? Instead we get this sensational and misleading title, and, yeah, it pisses me off.
Enough of this nonsense. I think the highly popular nature of the post, and the productive discussion that ensued, means that the post and headline were good. I certainly did the guy more good than harm, by bringing the attention of a community of hackers to this issue.
This reminds me of when I was editor of my college newspaper, and I wrote a headline that said "Student Raped in Gesling Stadium." The university and the campus cops all wanted us to say sexual assault and were pitching a fit. But we felt the strong language was justified, and we printed the word RAPE in big bold block letters. As a result, there was immediately hundreds of thousands of dollars spent on improving campus security.
In this case, I wrote that headline because I knew people would read it, and I knew that they wanted to read it, and I knew that they should read it. The last thing I was doing was trying to give the guy a hard time.
I think Bit Rot is pretty catchy.
I think both of you agree that the original author deserves only thanks.
Some of the stuff we find, like 1-in-80M core dumps are to be expected because they're so rare and most folks don't have that much test data. But many others could be found by simply running a parser against a few hundred random urls from the dmoz rdf. I wish more lib developers would do this.
http://code.google.com/p/html5lib/
Especially since html5lib is supposed to follow the HTML5 parsing rules, which were basically reverse-engineered from IE's HTML parsing, so they ought to work for every web-page in existence.
parser = html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("beautifulsoup"))
try:
document = parser.parse(response)
except Exception, e:
print 'parse failed ' + str(e)
returnHe could make an earnest attempt at finding other people to work on it and just do code reviews. Be a figure of advice and authority while doing no real work. That would be great IMHO.
sgmllib [done]
* Does not fully parse SGML.
* In the stdlib for support to htmllib which is slated for removal.
Based on that and the standard docs, it looks like it was lost in the standard library reorganization. The HTMLParser and other HTML-related libraries were merged into a new html module; sgmllib's parser was an incomplete implementation of SGML that only HTMLParser used, so apparently in the reorg it was found unnecessary and scrapped.Failing that, you can always use Perl and HTML::TreeBuilder / HTML::Parser. They work pretty well on malformed input.
import libxml2
parse_options = libxml2.HTML_PARSE_RECOVER + libxml2.HTML_PARSE_NOERROR + libxml2.HTML_PARSE_NOWARNING
xml_document = libxml2.readDoc(junk_html, None, None, parse_options)
clean_xhtml = xml_document.getRootElement().serialize()
Note: this method of "cleaning" works by building an XML tree out of HTML, except that HTML is not XML, so non-closed tags such as <textarea></textarea> will get closed and the browser puts any HTML after the tag into the textarea on the screen, so don't use this if you still want to output to a browser.EDIT: fixed formatting.