Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

i want to connect this page http://www.inchem.org/pages/cicads.html and to fill in the single text field (eg. 50-00-0) then follow the link and save the resulting page.
$mech->get($url); if ( $mech->success() ) { $mech->form_name( 'searchform' ); $mech->set_fields( QueryText => '50-00-0' ); #$mech->set_visible( '50-00-0' ); $mech->submit(); }
But I always get a html site that states

Error: Failed to obtain serverspec. Unable to determine the serverSpec from the environment variable VERITY_K2_HOSTPORT. Please set this env variable to point to the proper K2 Broker/Server serverspec.

Could you give me a hint? Thank you very much.

Replies are listed 'Best First'.
Re: WWW::Mechanize text field
by ikegami (Patriarch) on Sep 18, 2007 at 14:57 UTC

    That site uses JavaScript to set the hidden field serverSpec to the value charlie.ccohs.ca:9900. (At least for me.) WWW::Mechanize doesn't execute JavaScript, so this field doesn't get set.

    It could be some kind of load balancing system or a means of directing a user to the nearest mirror. The implementation keeps the actual search page (relatively) static. It would have been better if a default had been provided.

      Ah.. I knew.. again that ******* JavaScript. Thank you anyway.
        You should be able to set the serverSpec field as well even though it is hidden. My suggestion would be to check the headers to see if the server value changes often. If it appear to be the same it may be used to switch servers for testing or other purposes. If it changes often it is more likely used for load balancing. If it appears to be static you could just set the field to that value in your script. If it seems to change frequently you could still do that using one of the values. However but if it is used for load balancing you are doing an end run around it. If this script will be used a lot that would be impolite to say the least. The best approach in that case would be to find a way to get the dynamic value each time the script is run.