In Progress

Make this Form submission code work!

This code should do something very simple. It supposed to:

1. Run on my machine’s command line

2. Go to certain URL and emulate submitting a form via post

3. Receive a "Search Result" page.

4. Print out the result on stdout (for now)

That's all I am trying to do, but couldn't get it to work.

In my code bellow, I tried to use Get first to obtain hidden fields values, which I use in subsequent Post. I also set cookie too. The server responses to the post. But it sends back the “Home” page , instead of “Search Result” page I am expecting. The “Home” page is where I filled out the form in the first place.

User input value is only for 'address'field, which is hardcoded in the code (as 'PAULINE'...name of a street), which is perfectly fine since this is just a test piece of code.

What am I doing wrong? All you have to do is to make it work.

///////////////////////////////////////////////////

#!C:[url removed, login to view] -w

use LWP::UserAgent;

use HTTP::Cookies;

use URI::Escape ('uri_escape');

my $url= '[url removed, login to view]';

my $street_address = 'PAULINE'; # This is just a test, so use this

# hard coded street name

my $cookie_jar = HTTP::Cookies->new;

$cookie_jar->clear;

my $ua = LWP::UserAgent->new;

$ua->timeout(10);

# $ua->env_proxy;

$ua->cookie_jar($cookie_jar);

# We disguise ourselves as Internet Explorer

$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

$ua->timeout(30);

# Get the page first to get hidden session stuff

$resp = $ua->get(

$url

);

if ($resp->is_success) {

print "Got response for Get:n";

# print $resp->content;

}else {

die $resp->status_line;

}

my $viewstate;

my $eventvalidation;

my $previouspage;

# Copy these hidden field from the response from Get to use in the Post

$resp->content =~ /__VIEWSTATE" value="([^"]*)"/g;

$viewstate = $1;

$resp->content =~ /__PREVIOUSPAGE" value="([^"]*)"/g;

$previouspage = $1;

$resp->content =~ /__EVENTVALIDATION" value="([^"]*)"/g;

$eventvalidation = $1;

print 'VIEWSTATE: ',$viewstate,"n";

print 'EVENTVALIDATion: ', $eventvalidation, "n";

# Now post it

my $response = $ua->post(

$url,

[

'__EVENTTARGET' => '',

'__EVENTARGUMENT' => '',

'__VIEWSTATE' => $viewstate,

'ctl00x24cph1x24sq1x24Class_dropdown' =>

'1x2C2x2C3x2C4x2C5x2C6x2C7x2C8x2C9x2C10',

'ctl00x24cph1x24sq1x24Class_textbox' => '',

'ctl00x24cph1x24sq1x24Class' => '',

'ctl00x24cph1x24sq1x24Class_last' => '',

'ctl00x24cph1x24sq1x24ListingID_textbox' => '',

'ctl00x24cph1x24sq1x24ListingID' => '',

'ctl00x24cph1x24sq1x24ListingID_last' => '',

'ctl00x24cph1x24sq1x24_City_textbox' => '',

'ctl00x24cph1x24sq1x24_City' => '',

'ctl00x24cph1x24sq1x24_City_last' => '',

'ctl00x24cph1x24sq1x24_ListingArea_textbox' => '',

'ctl00x24cph1x24sq1x24_ListingArea' => '',

'ctl00x24cph1x24sq1x24_ListingArea_last' => '',

'ctl00x24cph1x24sq1x24_Address' => $street_address, # Looking for PAULINE

'ctl00x24cph1x24sq1x24PostalCode_textbox' => '',

'ctl00x24cph1x24sq1x24PostalCode' => '',

'ctl00x24cph1x24sq1x24PostalCode_last' => '',

'ctl00x24cph1x24sq1x24BedRange_dropdown' => '8',

'ctl00x24cph1x24sq1x24BedRange_textbox' => '',

'ctl00x24cph1x24sq1x24BedRange' => '',

'ctl00x24cph1x24sq1x24BedRange_last' => '',

'[url removed, login to view]' => 'Min',

'ctl00x24cph1x24sq1x24BathRange_dropdown' => '1',

'ctl00x24cph1x24sq1x24BathRange_textbox' => '',

'ctl00x24cph1x24sq1x24BathRange' => '',

'ctl00x24cph1x24sq1x24BathRange_last' => '',

'[url removed, login to view]' => 'Min',

'ctl00x24cph1x24sq1x24ListPrice_textbox' => '',

'ctl00x24cph1x24sq1x24ListPrice' => '',

'ctl00x24cph1x24sq1x24ListPrice_last' => '',

'[url removed, login to view]' => 'Max',

'ctl00x24cph1x24sq1x24StructureSize' => '',

'[url removed, login to view]' => 'Min',

'ctl00x24cph1x24sq1x24_LotSize' => '',

'[url removed, login to view]' => '1',

'[url removed, login to view]' => 'Min',

'ctl00x24cph1x24sq1x24butSearch.x' => '',

'ctl00x24cph1x24sq1x24butSearch.y' => '',

'ctl00x24cph1x24sq1x24txtInclude' => '',

'ctl00x24cph1x24sq1x24txtExclude' => '',

'__PREVIOUSPAGE' => $previouspage, #'4C-zcwd0nspWfWHBNoTD-g2',

'__EVENTVALIDATION' => $eventvalidation,

]

);

print '////////////////////////////////////////////////////////////////', "n";

if ($response->is_success) {

print $response->content; # PROBLEM! I get "Home" page instead of

# "Search Result" page

}

else {

die $response->status_line;

Skills: Perl

See more: perl lwp viewstate, lwp mlslistingscom, work ua, work home via internet, work home line, work c, submission page, place code, piece work home, no code, my code, make set, make line, got home work, internet code, home instead, first code, code line, code internet, code get, code 8, clear search fields, lwp viewstate, emulate post hidden viewstate, eventvalidation viewstate lwp

About the Employer:
( 1 review ) cupertino, United States

Project ID: #225223

Awarded to:

perldev123

Have a fix ready for you. Please check your PMB.

$45 USD in 1 day
(1 Review)
1.3

7 freelancers are bidding on average $112 for this job

dims

Look demo in PM

$50 USD in 1 day
(115 Reviews)
6.1
AmitKumarCal

Hi, Check PM

$250 USD in 2 days
(1 Review)
3.2
dhoss

Hey there, check your pm for details.

$90 USD in 1 day
(1 Review)
2.9
remate

I have fixed your code. Check PMB please.

$50 USD in 1 day
(9 Reviews)
2.8
suresh0912

Hi, check the PMB..

$250 USD in 5 days
(0 Reviews)
0.0
flintsoft

Can offer easy solution on VBS/JS or Perl.Thank you.

$50 USD in 2 days
(0 Reviews)
0.0