|
|
I want to get the html sourcecode from that page: http://bahn.ltur.com/index/search/?lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar=Hamburg+Dammtor&to_spar=Leipzig+Hbf&start_datum=01.07.2012&start_time=23%3A49&end_datum=01.07.2012&end_time=23%3A51&SEA_adults=1&trainclass_spar=2
I can access the site when i go to that url. i cannot get the sourcecode via curl. not in bash "curl -iL url > site.html" nor with that php script:i get the startpage (bahn.ltur.com).
Code for sending GET request- $ch=curl_init();
- curl_setopt($ch,CURLOPT_URL,'http://bahn.ltur.com/index/search/?lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar=Hamburg+Dammtor&to_spar=Leipzig+Hbf&start_datum=01.07.2012&start_time=23%3A49&end_datum=01.07.2012&end_time=23%3A51&SEA_adults=1&trainclass_spar=2');
- curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_exec($ch);
复制代码
//Answer:
First: get cookie from page (w/GET-params)Second: go to the details page and send the cookie.- /* get cookie */
- $ckfile = tempnam ("/tmp", "CURLCOOKIE");
- $ch=curl_init();
- curl_setopt($ch,CURLOPT_URL,'http://bahn.ltur.com/index/search/?lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar=Hamburg+Dammtor&to_spar=Leipzig+Hbf&start_datum=01.07.2012&start_time=23%3A49&end_datum=01.07.2012&end_time=23%3A51&SEA_adults=1&trainclass_spar=2');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_setopt($ch, CURLOPT_HEADER, TRUE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
- $html = curl_exec($ch);
- /* get page */
- $ch = curl_init("http://bahn.ltur.com/details");
- curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- echo $html;
- curl_close($ch);
复制代码
you should check the return value from curl_exec as well:- if ($html === false) {
- die("Curl error: " . curl_error($ch));
- }
复制代码
The point is:- curl_setopt($ch, CURLOPT_COOKIE, "BAHNSESSID= fd12a6c3d517c702eab0014879d551ef; bla=foo");
复制代码
|
|