I looked at the source code to the webpage. Then used a combination of guesswork, hacking and luck. I'm no guru at reading HTML page code. Basically I was looking for what actually happens with the "submit" button is pressed by the user. Other things happen like enforcing the 25,000 character limit which I didn't bother with.
When experimenting with my browser and examining the returned page source for a query, I noticed that this "sentiment" value is actually on the last line of the returned page and I wrote an ugly little hack to get that value. Of course this is "fragile", but then again it only took me a couple of minutes to do.
WWW::Mechanize can do a lot of this low level work for you, but I'm not as familiar with it. There is also a command line tool that can help build Mechanize scripts but I've forgotten the exact name of that thing right now. But I did play with some time ago and thought it was pretty cool, its written by Corion. I don't do these scripts very often. These are higher level tools that are probably a better way for you to start with. I'd google around for Mechanize and look at some of the cookbooks, etc. I think there are also various Firefox tools that can give you the contents of what the browser posts back to the server - but I didn't need them for this simple project.
I tried the suggestion given on the webpage (Curl) and it didn't work out so well, so I tried another way to give you some sort of a workable answer. I don't claim that it is the "best" answer, but it is an answer. Thanks for giving the URL that you were dealing with - actual code would not have been possible without that!
This is just a few snippets from the page source... take a look at the full thing with your browser if you are interested...here are a few places to focus your attention.
function doSubmit() {} the post back URL is in here...
futher down some HTML code...
looking for what happens when the "submit" button is pressed
<input type="button" id="submit" name="submit" value="Submit" onclick=
+"doSubmit()">
other code gives the language options...
Update: Now that you have a working example using lower level LWP, see if you can replicate the functionality with Mechanize. This stuff can get very tricky depending upon the website! I think it took me a whole week to get my first LWP program working! In terms of complexity, this site is one of the "easier" ones. However, expect to spend a considerable number of hours working on your first one. |