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

3
  • Possible duplicate of stackoverflow.com/questions/4589160/… Commented Jan 10, 2014 at 6: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? Commented Jan 10, 2014 at 6:17
  • Just did a quick answer... it should be close to what you need. The array should be your formfieldnames => valuesyouwanttopost Commented Jan 10, 2014 at 6:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.