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

≡放荡痞女 提交于 2019-12-25 01:27:15

问题


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.

Is there a way to use a Google API to do this programatically from PHP? Any other methods?

Thanks for any pointers.


回答1:


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.

With the Custom Search API, you have to create an app to receive an authorized API key. With that key, you get 100 free queries per day, and can get results in both JSON and ATOM formats.




回答2:


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.



来源:https://stackoverflow.com/questions/6740703/using-php-to-get-number-of-google-search-results-for-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!