2006-08-08 @ 15:51
More Ruby Mechanize Dev
I’ve been working away at mechanize lately. It seems like my creativity comes in bursts. As soon as I make a small bugfix release, I get inspired and write a whole bunch of stuff. Anyway, Eric pointed out that I didn’t have support for multi-select lists, so I added that for 0.5.2. I’m excited to release 0.5.3 already because I updated it so that when operating on an WWW::Mechanize::List, if the list doesn’t respond to the method being called, it will try it on the first element of the list. So, what does that mean? You can click on links without having to specify the first one all the time. You can do this:
Instead of doing this:
But it is still an array, so if you have multiple links with the text ‘Something’, you can index in to the array like so:
I’ve also been toying around with adding a “click” or “select” method to most objects. Then you can select the first radio button with either of the following lines:
agent.click form.radiobuttons.first form.radiobuttons.first.click
As for WWW::Mechanize 0.6.0, I’ve got Hpricot support in the trunk with all unit tests passing. This means that browsing the web and scraping those pages at the same time will be a breeze! I just hope that Why releases a gem for Hpricot on rubyforge soon! I also want to see if I can get Mechanize working with Selenium IDE so that scripts generated by Selenium IDE can be executed using mechanize and not through the browser.