简体   繁体   English

使用 PHP 获取字符串的谷歌搜索结果数量?

[英]Using PHP to get number of google search results for strings?

I want to run a PHP script that takes a list of strings, google searches them, and then returns to me (so I can insert into a database, write to a file, whatever) the number of search results.我想运行一个 PHP 脚本,它需要一个字符串列表,谷歌搜索它们,然后返回给我(这样我就可以插入数据库,写入文件,无论如何)搜索结果的数量。

Is there a way to use a Google API to do this programatically from PHP?有没有办法使用谷歌 API 从 PHP 以编程方式执行此操作? Any other methods?还有其他方法吗?

Thanks for any pointers.感谢您的任何指示。

The most straight forward way is to simply use contents of the websearch.最直接的方法是简单地使用网络搜索的内容。

foreach($list_of_strings as $string)
{
    $result_in_html = file_get_contents("http://www.google.com/search?q=$string");
    //parse the html however you see fit
}

However, a Custom Search API does exist.但是,确实存在自定义搜索 API

With the Custom Search API, you have to create an app to receive an authorized API key.使用自定义搜索 API,您必须创建一个应用程序才能接收授权的 API 密钥。 With that key, you get 100 free queries per day, and can get results in both JSON and ATOM formats.使用该密钥,您每天可以获得 100 次免费查询,并且可以获得 JSON 和 ATOM 格式的结果。

No, and if you use cURL to do this from your website, be prepared to get blacklisted by Google rather quickly as this is strictly against their TOS.不,如果您使用 cURL 从您的网站执行此操作,请准备好很快被 Google 列入黑名单,因为这严格违反他们的 TOS。

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

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