Jump to content

Archived

This topic is now archived and is closed to further replies.

Radek_1

Problem with Curl library, probably something happens in javascript?

Recommended Posts

Hello,

 

I want to download flight from Wizzair page.

I've checked all headers which are sended when browser "create" request (the same which Ryanair few months ago).

 

It looks like this in my browser:

I'm entering at https://wizzair.com/pl-PL/Search, select everything (from-to, date arrival and departure) then click "Send" and I've got results.

I've checked headers and I can see, that theres two requests to the following pages:

1) Search (here is created session ID saved in cookie, i've also sent POST parameters here), it returns error 302 then redirect to:
2) Select (theres no any post or get parameters, just requested session ID created before) and return results with flights.

 

I was trying to achieve the same results by curl. I created curl request with the same POST parameters to Search page. I save sessionId to cookie, also create the same cookies as in browser. Then enter to Select page, use cookies saved before but nothing happens.

First request return 302 error (the same happen in brower)

Second request returns default Wizzair website without flight results :(

 

If I use sessionId generated in my browser (not from curl request), second request show me correct results.

Why it doesn't work in curl? Is there any request processed and saved JavaScript which is not processed by curl method?

 

Code from my first requst where i'm sending post parameters in request

	$fields = array(
	'cookiePolicyDismissed' => 'true',
	'__EVENTTARGET' => 'HeaderControlGroupRibbonSelectView_AvailabilitySearchInputRibbonSelectView_ButtonSubmit', 
	'__VIEWSTATE' => '/wEPDwUBMGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFXEhlYWRlckNvbnRyb2xHcm91cFJpYmJvblNlbGVjdFZpZXckQXZhaWxhYmlsaXR5U2VhcmNoSW5wdXRSaWJib25TZWxlY3RWaWV3JFN0dWRldFNlbmlvckdyb3VwwAw35gayQedhYJ8oz+CHlR8x2gWGvNOEfHfCOBjF/lk=',
	'cff49415-63b6-4d31-b273-5eab61b6c327' => 'e2df7ef6-3abf-4eab-8110-51c30f30109a',
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24OriginStation' => $from,
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24DestinationStation' => $to,
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24DepartureDate' => $dateStart,
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24ReturnDate' => $dateBack,
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountADT' => '1',
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountCHD' => '0',
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24PaxCountINFANT' => '0',
	'WizzSummaryDisplaySelectViewRibbonSelectView%24PaymentCurrencySelector' => '00000000-0000-0000-0000-000000000000FULL',
	'HeaderControlGroupRibbonSelectView%24AvailabilitySearchInputRibbonSelectView%24ButtonSubmit' => 'Szukaj');

	//url-ify the data for the POST
	foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
	rtrim($fields_string,'&');
	

	//open connection
	$ch = curl_init();	
	//set the url, number of POST vars, POST data
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0');
	curl_setopt($ch, CURLOPT_HEADER,1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
												'Host: wizzair.com',
												'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/*;q=0.8',
												'Accept-Language: pl,en;q=0.7,en-us;q=0.3',
												'Connection: keep-alive'
												));
	
	curl_setopt($ch,CURLOPT_POST,count($fields));
	curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
	
	//execute post
	$result = curl_exec($ch);
		
	curl_close($ch);

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.