I want to extract data from a page with the DOMCrawler of Symfony2. This is the page where I want to get data from: http://kovv.mavari.be/kalender.aspx
But I want it after a post, when you click on 'zoek' (no parameters in dropdowns), that's the page I want! Now I have : $html = file_get_contents("http://kovv.mavari.be/kalender.aspx");
But obviously it will load the first page without a post. Is there a way that I can load the page with a post? or do I need to save the page to my local drive first?
UPDATE:
This is my code now:
$post = http_build_query(array(
'ctl00$ContentPlaceHolder1$ddlGeslacht' => 'Heren',
'ctl00$ContentPlaceHolder1$ddlReeks' => '',
'ctl00_ContentPlaceHolder1_ddlDatum' => ''
));
$options= array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $post
));
$context = stream_context_create($options);
$html = file_get_contents('http://kovv.mavari.be/kalender.aspx', false, $context);
But the html is still not changed, it's still the first page without post..
UPDATE 2: This is what I have now:
$url = "http://kovv.mavari.be/kalender.aspx";
$regs=array();
$cookies = '../src/VolleyScout/VolleyScoutBundle/Resources/doc/cookie.txt';
// regular expressions to parse out the special ASP.NET
// values for __VIEWSTATE and __EVENTVALIDATION
$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';
$regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data=curl_exec($ch);
$viewstate = $this->regexExtract($data,$regexViewstate,$regs,1);
$eventval = $this->regexExtract($data, $regexEventVal,$regs,1);
$postData = '__VIEWSTATE='.rawurlencode($viewstate)
.'&__EVENTVALIDATION='.rawurlencode($eventval)
.'&ctl00_ContentPlaceHolder1_ddlGeslacht=Heren'
.'&ctl00$ContentPlaceHolder1$ddlReeks'
.'&ctl00_ContentPlaceHolder1_ddlDatum'
.'&ctl00$ContentPlaceHolder1$btnZoek:zoek'
;
curl_setOpt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setOpt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
$data = curl_exec($ch);
echo $data;
curl_close($ch);
But I still get the page without a post, am I missing something?