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

Hello there lonely monks,

I am trying to write a short perl code to query for some info from the website below

http://www.sanmateocountytaxcollector.org/SMCWPS/pages/secureSearch.jsp

I used the perl code below:
#!/usr/bin/perl -w # Create a user agent object use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # Create a request my $req = HTTP::Request->new(POST => 'http://www.sanmateocountytaxco +llector.org/SMCWPS/pages/secureSearch.jsp'); $req->content_type('application/x-www-form-urlencoded'); $req->content('query=libwww-perl&mode=dist'); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; }
how do I pass the paramenter to the search? for example, if I manually do it, I might type in 055 023 010 and click the search button. I have read that the parameters are passed on the address field but for some reason I do not see it. How can I find out the exact line passed to the server for the search?

Thanks for any help you can provide.

Replies are listed 'Best First'.
Re: What parameters should I send?
by moritz (Cardinal) on Dec 06, 2010 at 08:28 UTC
    how do I pass the paramenter to the search?

    There are two possible approaches: The first is to read the HTML (+javascript) source of the page, understand what it's doing, and emulate the same in Perl.

    The second is to get a copy of the HTTP request that your browser sends when you submit the form. This can be done with tools like wireshark, or with the Live HTTP Headers extension for Firefox.

      I downloaded LiveHttpHeader as you said and ran it. Here is the result that I got but am unable to determine the exact line that was sent, could you help me out please.
      http://www.sanmateocountytaxcollector.org/SMCWPS/SearchParcels POST /SMCWPS/SearchParcels HTTP/1.1 Host: www.sanmateocountytaxcollector.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.11) Gecko +/20101028 CentOS/3.6-2.el5.centos Firefox/3.6.11 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0. +8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://www.sanmateocountytaxcollector.org/SMCWPS/pages/secure +Search.jsp Cookie: JSESSIONID=0000hccwV8X_iqYt4J9YpcxAwwC:-1 Content-Type: application/x-www-form-urlencoded Content-Length: 181 parcelNumber=048022230&searchType=parcel&listFirst=S&bkList=SS&address +TypeDsp=&addressType=&actionType=search&nextPage=.%2Fpages%2FparcelLi +st.jsp&parcel1=048&parcel2=022&parcel3=230
        parcelNumber=048022230&searchType=parcel&listFirst=S&bkList=SS&addressTypeDsp=&addressType=&actionType=search&nextPage=.%2Fpages%2FparcelList.jsp&parcel1=048&parcel2=022&parcel3=230

        That's the list of POST parameters and their values. If you replicate them, you should be fine.

Re: What parameters should I send?
by perl_lover (Chaplain) on Dec 06, 2010 at 09:23 UTC
Re: What parameters should I send?
by Anonymous Monk on Dec 06, 2010 at 22:22 UTC
    Thanks Monks, just the right tools for the holiday.