gpt4 book ai didi

php - 将 CURL 与 Google 结合使用

转载 作者:行者123 更新时间:2023-12-02 17:55:01 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com