简体   繁体   English

在php中使用curl从网站获取针对特定请求的响应?

[英]Getting a response from a website for a particular request using curl in php?

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.. 所以这是我要向erail.in网站提出的要求。

How can I get response from that site and display it in my webpage.. using cURL in php.. please help me...thanx in advance.. 我如何才能从该站点获得响应并将其显示在我的网页中。.在php中使用cURL ..请帮助我...谢谢。

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.. 我是新手。.我想学习并提供一些链接。.如何继续进行以及如何使用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.. 但这会直接显示整个网页...请帮助我,我必须学习这个..但我什么也没得到。

This particular site is dynamically loading the data with JavaScript, and the data is returned mostly as a bunch of numbers and codes. 这个特定的站点正在使用JavaScript动态加载数据,并且数据大多以一堆数字和代码的形式返回。 In order to scrape it, you would have to figure out how to properly form the URL for each request. 为了抓取它,您将必须弄清楚如何正确地为每个请求形成URL。

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. 最好的政策是与公司沟通您想做什么。

you can not get details from erail.in, because erail.in does not provide any API facility. 您无法从erail.in获取详细信息,因为erail.in不提供任何API功能。 But IRCTC provide API to get train details, but it is not free of cost. 但是IRCTC提供API来获取火车详细信息,但这并不是免费的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM