php - 将 CURL 与 Google 结合使用

标签 php curl

我想 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/

相关文章:

php - 如何使用 Google SpreadSheets API 将数据提供给应用程序?

php - 使用 jquery 的一页 Codeigniter 站点? Ajax ?

php - 在Wordpress网站上引用MYSQL数据库中的数据

PHP Excel 在单击启用编辑之前为公式单元格提供空白输出

Git http.cookiefile 配置选项不起作用

phpcurl ssl验证

php - 如何下载并解析网页的一部分?

php - 使用 mysql_fetch_object

ubuntu - 如何通过 curl 解决 SSL 超时问题?

PHP CURL 请求失败,出现 503 错误