【发布时间】:2016-06-24 21:52:23
【问题描述】:
我无法在 php 中使用 cURL 获取数据,因为我可以在终端中使用curl 命令来执行此操作,如下所示 -
curl http://www.universalapplianceparts.com/search.aspx?find=w10130694
此命令在终端中提供预期结果。
我希望使用 curl 在 php 中得到相同的结果
下面是我的 php 代码 -
$url = "http://www.universalapplianceparts.com/search.aspx?find=W10130694";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.universalapplianceparts.com/");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec ($ch);
curl_close ($ch);
var_dump($output);
请让我知道为什么我在终端中使用 php curl 没有得到相同的结果。
谢谢
【问题讨论】:
-
你想通过这个做什么?
-
当我进入终端时,我想在浏览器中获取 html 数据。我认为 php 代码中缺少一些东西
-
据我所知,您正在使用 POST,而您实际上想要 GET。我认为如果您将 POST 更改为 GET 并删除 postfields 和标题行,它应该可以工作......
-
检查更新的答案。
标签: php curl web-scraping libcurl