Friday, December 6, 2013

Start searching with python google module .

You can use python google module to start searching anything using this module.

First you need to install the python module using pip.

# pip install google
Downloading/unpacking google
  Running egg_info for package google
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 
in /usr/local/lib/python2.7/dist-packages (from google)
Installing collected packages: google
  Running install for google
    changing mode of build/scripts-2.7/ from 644 to 755
    changing mode of /usr/local/bin/ to 755
Successfully installed google
Cleaning up...

As you can see the next step is to upgrade: beautifulsoup4 ...

# pip install --upgrade beautifulsoup4
Downloading/unpacking beautifulsoup4 from
  Downloading beautifulsoup4-4.3.2.tar.gz (143Kb): 143Kb downloaded
  Running egg_info for package beautifulsoup4
Installing collected packages: beautifulsoup4
  Found existing installation: beautifulsoup4 4.3.1
    Uninstalling beautifulsoup4:
      Successfully uninstalled beautifulsoup4
  Running install for beautifulsoup4
Successfully installed beautifulsoup4
Cleaning up...

Let's make a simple script to find linux word using ...

>>> from google import search
>>> for url in search('linux', tld='com', lang='en', stop=2):
...     print(url)

If you want to know more about google search function then use this:

>>> help(
Help on function search in module google:

search(query, tld='com', lang='en', num=10, start=0, stop=None, pause=2.0)
    Search the given query string using Google.

... and this is all.