我想 CURL 到 Google 以查看它为特定搜索返回了多少结果。
我已经尝试过这个:
$url = "http://www.google.com/search?q=".$strSearch."&hl=en&start=0&sa=N";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$response = curl_exec($ch);
curl_close($ch);
但它只是返回 405 Method Allowed google 错误。
有什么想法吗?
谢谢
最佳答案
使用 GET 请求而不是 POST 请求。即去掉
curl_setopt($ch, CURLOPT_POST, true);
或者更好的是,使用他们的 well defined search API而不是屏幕抓取。
关于php - 将 CURL 与 Google 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2968866/