Tonight, I was struck by an urge to JFDI. For a long time, I've wanted a better way to organize my Netflix queue. There used to be Netflix Freak, which was decent, but cost money, and I think it went away. I think it had other problems, I just can't remember anymore.
Anyway, what I really wanted was a way to save my queue to a text file, edit the file, and then upload it again. It should have been simple, but the form used on Netflix is pretty ugly, and I was having a hell of a time figuring out how to deal with it using TokeParser, which is built in to Mech. I knew it wasn't the right sort of parser, but I didn't know what was better. Finally, I asked #perl where I could get something to say "for each div of class foo, do X." DrForr pointed me toward HTML::Tree, which made this task incredibly simple.
Now I can save my queue, rearrange the file, and update my queue. No more trying to remember what number I put in front of what, no more trying to keep lots of changes in my head at once. I put the lines in the order I want and hit "go!" It doesn't delete or add movies yet, but I may (or may not) add that. Tomorrow I'll probably collect these two little hacks into one program with some command line switches.
In the meantime, I would like everyone to know that Sean Burke and Andy Lester deserve candy and hugs for giving away such great toolkits.
My hammer of choice is forcing the input to XHTML using HTMLTidy, then attacking it with XPath. XPath rocks extremely hard. HTML::Tidy (there’s Andy Lester again) and XML::LibXML are excellent tools for this approach.
Tidy first?
grantm on 2005-09-16T20:56:57
Do you really need to tidy first? I just make sure recover mode is turned on and use LibXML's parse_html method - works for me. Maybe you have to deal with uglier HTML than I do.Re:Tidy first?
Aristotle on 2005-09-16T22:18:24
I didn’t think of that because I actually use XSLT most of the time (nowadays a Perl wrapper script around XML::LibXSLT and the aforementioned modules), and there’s something really strange going on with namespaces in a DOM built using libxml’s HTML parser, which causes strange misbehaviour in XSL transforms that I never figured out (just had hours of debugging fun with). When I started out, I didn’t even have the option because I was in fact using libxslt’s
xsltproc
utility, and that doesn’t even a way to parse HTML input.If you’re actually just parsing the input using libxml and then do all the work in Perl, you can probably get away without turning things into XHTML first, you’re right.
Re:One more step...
rjbs on 2005-09-16T12:07:11
Actually, what I did was create:getQueue and :pushQueue. I think that I'm more comfortable being explicit: I don't want to hit the wrong few keys and accidentally delete all the movies from my queue!