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.

In reply to Re^3: Passing Values to a webpage and retrieving an answer by Marshall
in thread Passing Values to a webpage and retrieving an answer by nateg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.