项目作者: howie6879

项目描述 :
Google search results crawler, get google search results that you need - php
高级语言: PHP
项目地址: git://github.com/howie6879/php-google.git
创建时间: 2017-06-22T14:10:58Z
项目社区:https://github.com/howie6879/php-google

开源协议:

下载


php-google

This is an easy Google Searching crawler that you can get anything you want in the page by using it.

During the process of crawling,you need to pay attention to the limitation from google towards ip address and the warning of exception , so I suggest that you should pause running the program and own the Proxy ip

python - MagicGoogle

2.How to Use?

This project can be installed via composer by requiring the howie6879/php-google package in composer.json:

  1. {
  2. "require": {
  3. "howie6879/php-google": "1.0"
  4. }
  5. }

If you have installed php-google in your project, you can get google search results that you need.

Example

  1. # Add boostrap autoload file
  2. require_once '../vendor/autoload.php';
  3. use \howie6879\PhpGoogle\MagicGoogle;
  4. # Or new MagicGoogle()
  5. $magicGoogle = new MagicGoogle('http://127.0.0.1:8118');
  6. # The first page of results
  7. $data = $magicGoogle->search_page('python');
  8. # Get url
  9. $data = $magicGoogle->search_url('python');
  10. foreach ($data as $value) {
  11. var_dump($value);
  12. }
  13. /** Output
  14. * string(23) "https://www.python.org/"
  15. * string(33) "https://www.python.org/downloads/"
  16. * string(35) "https://docs.python.org/3/tutorial/"
  17. * string(44) "https://www.python.org/about/gettingstarted/"
  18. * string(43) "https://wiki.python.org/moin/BeginnersGuide"
  19. * string(41) "https://www.python.org/downloads/windows/"
  20. * string(24) "https://docs.python.org/"
  21. * string(59) "https://en.wikipedia.org/wiki/Python_(programming_language)"
  22. * string(39) "https://www.codecademy.com/learn/python"
  23. * string(25) "https://github.com/python"
  24. * string(38) "https://www.tutorialspoint.com/python/"
  25. * string(28) "https://www.learnpython.org/"
  26. * string(44) "https://www.programiz.com/python-programming"
  27. */
  28. # Get {'title','url','text'}
  29. $data = $magicGoogle->search('python', 'en', '1');
  30. foreach ($data as $value) {
  31. var_dump($value);
  32. }
  33. /** Output
  34. * array(3) {
  35. * ["title"]=>
  36. * string(21) "Welcome to Python.org"
  37. * ["url"]=>
  38. * string(23) "https://www.python.org/"
  39. * ["text"]=>
  40. * string(54) "The official home of the Python Programming Language. "
  41. * }
  42. */

You can see sample.php

If you need a big amount of querie but only having an ip address,I suggest you can have a time lapse between 5s ~ 30s.

The reason that it always return empty might be as follows:

  1. <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
  2. <TITLE>302 Moved</TITLE></HEAD><BODY>
  3. <H1>302 Moved</H1>
  4. The document has moved
  5. <A HREF="https://ipv4.google.com/sorry/index?continue=https://www.google.me/s****">here</A>.
  6. </BODY></HTML>