Crawling Google Search with PHP

前端 未结 3 850
暖寄归人
暖寄归人 2021-02-02 04:52

I trying to get my head around how to fetch Google search results with PHP or JavaScript. I know it has been possible before but now I can\'t find a way.

I am trying to

3条回答
  •  粉色の甜心
    2021-02-02 05:11

    There is php a github package named google-url that does the job.

    The api is very comfortable to use. See the example :

    // this line creates a new crawler
    $googleUrl=new \GoogleURL\GoogleUrl();
    $googleUrl->setLang('en'); // say for which lang you want to search (it could have been "fr" instead)
    $googleUrl->setNumberResults(10); // how many results you want to check
    // launch the search for a specific keyword
    $results = $googleUrl->search("google crawler");
    // finaly you can loop on the results (an example is also available on the github page)
    

    However you will have to think to use a delay between each query, or else google will consider you as a bot and ask you for a captcha that will lock the script.

提交回复
热议问题