Reputation: 7
Can anyone please tell me how to : a user gives source,destination and date and requests the availbale trains? so this is the request I want to make to erail.in website..
How can I get response from that site and display it in my webpage.. using cURL in php.. please help me...thanx in advance..
I'm new to this stuff..I want to learn and also provide me some links..how to proceed with and what all can I do with curl..
I have tried like this..
$params=array(
'txtStationFrom'=>'SC',
'txtStationTo'=>'MAS',
'adate'=>'26-6-2013'
);
$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, "www.erail.in");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($curl);
print $result;
?>
But this directly displays the whole webpage... please help me I have to learn this..and I'm not getting anything..
Upvotes: 0
Views: 523
Reputation: 7795
This particular site is dynamically loading the data with JavaScript, and the data is returned mostly as a bunch of numbers and codes. In order to scrape it, you would have to figure out how to properly form the URL for each request.
Here's a sample of the data returned:
Central~BCT~16.30~08.35~16.05~1111111~~~~~~~~1110000000~~~~~~~~~~~RAJDHANI~9012~2~1~0~2013-06-06~2018-06-07~1384~86~RAJDHANI:1384:4065,2250,2615,0,2250,0:2395,1345,1555,415,1345,0:1725,1005,1150,365,1005,0:0,0,0,0,0,0:0,0,0,0,0,0:0,0,0,0,0,0:0,0,0,0,0,0:0,0,0,0,0,0:0,30,0,0,0,0~0~0~~60~1~2952~Composition of Train: 1A-1,2A-4,3A-9,PC-2
Scraping should be done responsibly so as not to overload the server. The best policy is to communicate with the company about what you want to do.
Upvotes: 1
Reputation: 1869
you can not get details from erail.in, because erail.in does not provide any API facility. But IRCTC provide API to get train details, but it is not free of cost.
Upvotes: 0