February 23, 2011

Easy DOM parsing with Mojo::DOM

Long ago, I used regex's to parse HTML.

They told me it was evil. They told me it was not maintainable. They were right.

But the alternatives were painful. They were clunky. They required me to change the way I approached HTML. They required me to abandon the hipness of css selectors I had embraced with javascript libraries, and ignore the many years spent perfecting my css-foo.

HTML::Parser, HTML::TreeBuilder, I'm sure you're brilliant in your own way. I'm sure you have conquered many lands, and for those who wanted to adapt to your mindset, you brought much happiness.

I wanted a simpler way. jQuery taught us that css selectors are that better way.

Fortunately, Mojo::DOM sprouted up out of the land of Mojolicious and cookies and rainbows and unicorns.

Seriously, have you ever seen HTML retrieved, parsed, and processed so nicely in Perl?

Since most of you have used jQuery and/or similiar Javascript libraries, you already know how to use Mojo::UserAgent/DOM. You simply apply your existing Perl & Javascript knowledge, and you're done.

You're not relegated to parsing only web-requested data; you can use Mojo::DOM directly:

Installing is one-step easy:

curl -L get.mojolicio.us | sh

So now you know: you can leave the cruftiness behind, and hang with the hippest of the hip - there's no need to hide your head in shame when talking with hipsters about the latest Ruby shine. Shine is external; your Mojo runs deep.

Mojo::DOM docs

comments powered by Disqus