0

I have an aspx page here. The page has a form with a post action:

<form name="form1" method="post" action="Average1_web.aspx" id="form1">

The result after submitting the form is itself an aspx page (Report_For_mthly_avg_Zonewise.aspx).

I need to scrape the data from the result page for all the permutations and combinations of the form inputs. Is there any way that I can get the result of the post method in a php string rather than in the page (Report_For_mthly_avg_Zonewise.aspx)?

Thanks

Community
  • 1
  • 1
user1517108
  • 2,395
  • 6
  • 32
  • 43
  • Possible duplicate of http://stackoverflow.com/questions/4589160/using-curl-to-submit-retrieve-a-forms-results – Mattt Jan 10 '14 at 06:00
  • not much idea about curl...but in the link that you sent, where is the relationship between the curl code and the form being defined? – user1517108 Jan 10 '14 at 06:17
  • Just did a quick answer... it should be close to what you need. The array should be your formfieldnames => valuesyouwanttopost – Mattt Jan 10 '14 at 06:22

1 Answers1

1
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "yourform.php"); 
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('field1' => 'val1','field2' => 'val2','field3' => 'val3','field4' => 'val4'));
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($ch);
  echo $result;

$result will hold the html code for the page the form lands on after submit... so the page you want to scrape.

Mattt
  • 1,780
  • 14
  • 15
  • tried using it... but didnt work...blank screen. Relevant lines: curl_setopt($ch, CURLOPT_URL, "Average1_web.aspx"); and second one curl_setopt($ch, CURLOPT_POSTFIELDS, array('ddltype'=>'Retail','lbxzone' => 'NORTH ZONE','lbxcomm' => 'Wheat','ddlmonth1' => 'January','ddly1' => '2014','rbltype' => 'Average Price Report')); – user1517108 Jan 13 '14 at 04:36