🔍 Google Search unofficial API for Python with no external dependencies

Overview

Python Google Search API

Version Build Status

Unofficial Google Search API for Python.

It uses web scraping in the background and is compatible with both Python 2 and 3.

Why this project?

No such library exists which works out of the box i.e. without requiring any external dependencies. I did this so that I can use it on my Alfred workflow. But this turned out to be pretty generic, feel free to use it for your own work.

Features

  • Free unrestricted API, requires no key or credit card
  • Unicode support
  • Works for all Python versions (2 & 3)

Installation

pip install gsearch

NOTE: By using this library, you agree to its Terms and Conditions.

Using

> from gsearch.googlesearch import search

> results = search('Full Stack Developer')  # returns 10 or less results
[ ('Name', 'Link'),
	('Name', 'Link'),
	... ]

> results = search('Avi Aryan', num_results=20)  # returns 20 or less results

You can also use it as a CLI tool.

$ gsearch "君の名"

1. 映画『君の名は。』公式サイト
	http://www.kiminona.com/
2. 君の名は。 - Wikipedia
	https://ja.wikipedia.org/wiki/%25E5%2590%259B%25E3%2581%25AE%25E5%2590%258D%25E3%2581%25AF%25E3%2580%2582
3. 君の名は。 : 作品情報 - 映画.com
	http://eiga.com/movie/83796/
4. 君の名は。 - 作品 - Yahoo!映画
	https://movies.yahoo.co.jp/movie/%25E5%2590%259B%25E3%2581%25AE%25E5%2590%258D%25E3%2581%25AF%25E3%2580%2582/355058/
5. 『君の名は。』米メディア“矛盾”を指摘しつつも「一流」と絶賛 | dmenu映画
	https://movie.smt.docomo.ne.jp/article/1053874/
6. 「君の名は。」予告 - YouTube
	https://www.youtube.com/watch%3Fv%3Dk4xGqY5IDBE
7. 君の名はのネタバレ - 【君の名は。】あらすじやネタバレから舞台の聖地 ...
	https://tabichannel.com/article/102/kiminona
8. 『君の名は。』の深すぎる「15」の盲点 | シネマズ by 松竹
	https://cinema.ne.jp/recommend/kiminonaha2016092717/
9. Amazon.co.jp: 君の名は: DVD - アマゾン
	https://www.amazon.co.jp/b%3Fnode%3D5276458051

Examples

>>> from gsearch.googlesearch import search
>>> search('Python')
[('Welcome to Python.org', 'https://www.python.org/'), ('Python (programming language) - Wikipedia', 'https://en.wikipedia.org/wiki/Python_(programming_language)'), ('Python tutorial - TutorialsPoint', 'https://www.tutorialspoint.com/python/'), ('Learn Python (Programming Tutorial for Beginners) - Programiz', 'https://www.programiz.com/python-programming'), ('Learn Python | Codecademy', 'https://www.codecademy.com/learn/learn-python'), ('Learn Python | Codecademy', 'https://www.codecademy.com/en/courses/learn-python/lessons/python-syntax/exercises/welcome'), ('Introduction · A Byte of Python', 'https://python.swaroopch.com/'), ('Solve Introduction Questions | Python | HackerRank', 'https://www.hackerrank.com/domains/python')]
>>>
>>> search('Google Search API', num_results=15)
[('Custom Search JSON/Atom API | Custom Search | Google Developers', 'https://developers.google.com/custom-search/json-api/v1/overview'), ('Custom Search | Google Developers', 'https://developers.google.com/custom-search/'), ('Using REST to Invoke the API | Custom Search | Google Developers', 'https://developers.google.com/custom-search/json-api/v1/using_rest'), ('Custom Search Engine - Google', 'https://www.google.com/cse/'), ('What are the alternatives now that the Google web search API has ...', 'https://stackoverflow.com/questions/4082966/what-are-the-alternatives-now-that-the-google-web-search-api-has-been-deprecated'), ('Is there an API for Google search results? - Quora', 'https://www.quora.com/Is-there-an-API-for-Google-search-results'), ('Fetch Google Search Results with the Site Search API - CtrlQ.org', 'https://ctrlq.org/code/20076-google-search-api'), ('Google Custom Search API | ProgrammableWeb', 'https://www.programmableweb.com/api/google-custom-search'), ('Google Search API Alternative | Webhose.io', 'https://webhose.io/google-search-api-alternative'), ('FAROO - Free Search API', 'http://www.faroo.com/hp/api/api.html'), ("Google's Ajax Search API | Search Engine Watch", 'https://searchenginewatch.com/sew/news/2056817/googles-ajax-search-api'), ('Search | GitHub Developer Guide', 'https://developer.github.com/v3/search/'), ('Using the Google SOAP Search API - SEO Chat', 'http://www.seochat.com/c/a/google-optimization-help/using-the-google-soap-search-api/')]

Warning

Overusing this library might lead to your IP being blocked by Google Search servers. Searches through Chrome or another browser might still work but this library will stop working. I recommend keeping a 15 seconds gap after each usage of this library. In most cases, much lower gaps or even continuous use of the library will still work but still this is something to be kept in mind. If you see a 'rate limit' or a 503 error, it's best to stop using the library and try back after some time (~1 minute).

Inspiration

google by Mario Vilas - A library which does almost the same thing except that it uses external dependencies. This library also has some additional optimizations to reduce the chances of hitting rate limit.

Comments
  • Error importing gsearch

    Error importing gsearch

    Tested on both Windows & MacOs

    `from gsearch import googlesearch

    results = search('Hallo!', num_results=20)

    print(results)`

    Traceback (most recent call last): File ".\gsearch.py", line 1, in from gsearch import googlesearch File "C:\Users\Daniel\Desktop\Qarebase\gsearch.py", line 1, in from gsearch import googlesearch ImportError: cannot import name 'googlesearch' from 'gsearch' (C:\Users\Daniel\Desktop\Qarebase\gsearch.py)

    opened by SimplyPancake 2
  • [Feature request] Python 3.3 support

    [Feature request] Python 3.3 support

    1. Request

    It would be nice, if Python-GSearch will support Python 3.3.

    2. Justification

    I write plugin for Sublime Text 3 for scraping first link in Google SERP. Python-GSearch — is only Python module for Google SERP scraping, that works for me in Python 3.6.4 interpreter without bugs. Thank you very much!

    But Sublime Text 3 have environment, based on Python 3.3. See reasons, because Sublime Text developers not migrated to 3.6 in these topics:

    Plugin developers can't use modules, not compatible with Python 3.3.

    3. Settings

    For example, I write simple plugin:

    import sublime_plugin
    
    from gsearch.googlesearch import search
    
    
    class GoogleSearchCommand(sublime_plugin.TextCommand):
    
        def run(self, edit):
    
            results = search('kristinitaluckylife', num_results=1)
            r = results[0][1]
            print(r)
    
    

    4. Steps to reproduce

    I run GoogleSearchCommand in Sublime Text 3.

    5. Expected behavior

    As in interpreter:

    >>> from gsearch.googlesearch import search
    >>> results = search('kristinitaluckylife', num_results=1)
    >>> r = results[0][1]
    >>> r
    'http://www.thepictaram.club/instagram/kristinitaluckylife'
    >>> 
    

    6. Actual behavior

    Traceback (most recent call last):
      File "C:\Python36\Lib\site-packages\gsearch\googlesearch.py", line 14, in <module>
        from html import unescape
    ImportError: cannot import name unescape
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:\Sublime Text 3 x64\sublime_plugin.py", line 109, in reload_plugin
        m = importlib.import_module(modulename)
      File "./python3.3/importlib/__init__.py", line 90, in import_module
      File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
      File "<frozen importlib._bootstrap>", line 1022, in load_module
      File "<frozen importlib._bootstrap>", line 1003, in load_module
      File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
      File "<frozen importlib._bootstrap>", line 868, in _load_module
      File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
      File "D:\Sublime Text 3 x64\Data\Packages\TestPlugin\example.py", line 3, in <module>
        from gsearch.googlesearch import search
      File "C:\Python36\Lib\site-packages\gsearch\googlesearch.py", line 23, in <module>
        import urllib2 as request
    ImportError: No module named 'urllib2'
    

    I read, that function was introduced in Python 3.4, not in Python 3.3.

    Thanks.

    opened by Kristinita 2
  • Even on 1st time use, got no results.

    Even on 1st time use, got no results.

    I wrote such a simple function and ran it. It returned an empty array. This was my 1st time using the module so shouldn't be a rate-limiting thing. I also waited for a long time and retried, still no results. Any help?

    from gsearch.googlesearch import search
    
    result = search('Python', num_results=2)
    print(result)
    
    opened by KrishGarg 1
  • Updates user agents so google returns the proper results.

    Updates user agents so google returns the proper results.

    With a given search, the old user agents makes google return the javascriptless result. (And with so, the library is unable to parse the results).

    As far as I can tell, this new ones doesn't have the issue.

    Here are the results that the library is able to parse, followed by the user-agent. (The later ones being the new ones).

    0 - With agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) 0 - With agent Googlebot/2.1 (+http://www.google.com/bot.html) 11 - With agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36 0 - With agent Gigabot/3.0 (http://www.gigablast.com/spider.html) 0 - With agent Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR) AppleWebKit/533.3 (KHTML, like Gecko) QtWeb Internet Browser/3.7 http://www.QtWeb.net 0 - With agent Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 0 - With agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.2 (KHTML, like Gecko) ChromePlus/4.0.222.3 Chrome/4.0.222.3 Safari/532.2 0 - With agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4pre) Gecko/20070404 K-Ninja/2.1.3 0 - With agent Mozilla/5.0 (Future Star Technologies Corp.; Star-Blade OS; x86_64; U; en-US) iNet Browser 4.7 0 - With agent Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201 11 - With agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080414 Firefox/2.0.0.13 Pogo/2.0.0.13.6866 10 - With agent WorldWideweb (NEXT)

    10 - With agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36 10 - With agent Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36 11 - With agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36 11 - With agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) 11 - With agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) 11 - With agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 11 - With agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134 11 - With agent Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko 11 - With agent Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

    opened by EndermanAPM 0
  • Search return with no results.

    Search return with no results.

    https://github.com/aviaryan/python-gsearch/blob/fba2f42fbf4c2672b72d05b53120adcb25ba8b69/gsearch/googlesearch.py#L120

    Is effectively destroying the results on son querys. When searching for: 170PP+270PP Returns the url https://books.google.es/books?id=XZd2DwAAQBAJ&amp[...] re.sub(r'^.*?=', '', url, count=1) Severs the url to: XZd2DwAAQBAJ&pg=PA283&amp[...]

    What is the intended use of this line? Shouldn't it raise an exception when the return value is not valid?

    opened by EndermanAPM 4
  • Rewrite parsing using html.parser

    Rewrite parsing using html.parser

    Right now parsing is being done using regex. We should use the inbuilt html.parser instead.

    Python 2: https://docs.python.org/2/library/htmlparser.html Python 3: https://docs.python.org/3/library/html.parser.html

    Hacktoberfest 
    opened by aviaryan 0
Owner
Avi Aryan
Senior Software Engineer at @toptal, Past GSoC Mentor
Avi Aryan
rewise is an unofficial wrapper for google search's auto-complete feature

rewise is an unofficial wrapper for google search's auto-complete feature

Somdev Sangwan 71 Jul 19, 2022
First Party data integration solution built for marketing teams to enable audience and conversion onboarding into Google Marketing products (Google Ads, Campaign Manager, Google Analytics).

Megalista Sample integration code for onboarding offline/CRM data from BigQuery as custom audiences or offline conversions in Google Ads, Google Analy

Google 76 Dec 29, 2022
(unofficial) Googletrans: Free and Unlimited Google translate API for Python. Translates totally free of charge.

Googletrans Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make

Suhun Han 3.2k Jan 4, 2023
The unofficial Amazon search CLI & Python API

amzSear The unofficial Amazon Product CLI & API. Easily search the amazon product directory from the command line without the need for an Amazon API k

Asher Silvers 95 Nov 11, 2022
Open Source Discord bot with many cool features like Weather, Balance, Avatar, User, Server, RP-commands, Gif search, YouTube search, VK post search etc.

Сокобот Дискорд бот с открытым исходным кодом. Содержит в себе экономику, полезные команды (!аватар, !юзер, !сервер и тд.), рп-команды (!обнять, !глад

serverok 2 Jan 16, 2022
An unofficial client library for Google Music.

gmusicapi: an unofficial API for Google Play Music gmusicapi allows control of Google Music with Python. from gmusicapi import Mobileclient api = Mob

Simon Weber 2.5k Dec 15, 2022
An unofficial client library for Google Music.

gmusicapi: an unofficial API for Google Play Music gmusicapi allows control of Google Music with Python. from gmusicapi import Mobileclient api = Mob

Simon Weber 2.5k Dec 15, 2022
An API wrapper for Henrik's Unofficial VALORANT API

ValorantAPI.py An API wrapper for Henrik's Unofficial VALORANT API Warning!! This project is still in beta and only contains barely anything yet. If y

Jakkaphat Chalermphanaphan 0 Feb 4, 2022
This package accesses nitrotype's official api along with its unofficial user api

NitrotypePy This package accesses nitrotype's official api along with its unofficial user api. Currently still in development. Install To install, run

The Moon That Rises 2 Sep 4, 2022
Google scholar share - Simple python script to pull Google Scholar data from an author's profile

google_scholar_share Simple python script to pull Google Scholar data from an au

Paul Goldsmith-Pinkham 9 Sep 15, 2022
domhttpx is a google search engine dorker with HTTP toolkit built with python, can make it easier for you to find many URLs/IPs at once with fast time.

domhttpx is a google search engine dorker with HTTP toolkit built with python, can make it easier for you to find many URLs/IPs at once with fast time

Naufal Ardhani 59 Dec 4, 2022
google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Google APIs 36 Nov 22, 2022
An attendance bot that joins google meet automatically according to schedule and marks present in the google meet.

Google-meet-self-attendance-bot An attendance bot which joins google meet automatically according to schedule and marks present in the google meet. I

Sarvesh Wadi 12 Sep 20, 2022
Google Drive, OneDrive and Youtube as covert-channels - Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram

covert-control Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram using Python to create the files and the lis

Ricardo Ruiz 52 Dec 6, 2022
Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Antônio Oliveira 1 Nov 21, 2021
Unofficial GoPro API Library for Python - connect to GoPro via WiFi.

GoPro API for Python Unofficial GoPro API Library for Python - connect to GoPro cameras via WiFi. Compatibility: HERO3 HERO3+ HERO4 (including HERO Se

Konrad Iturbe 1.3k Jan 1, 2023
Unofficial Python wrapper for official Hacker News API

haxor Unofficial Python wrapper for official Hacker News API. Installation pip install haxor Usage Import and initialization: from hackernews import H

null 147 Sep 18, 2022
Unofficial Medium Python Flask API and SDK

PyMedium - Unofficial Medium API PyMedium is an unofficial Medium API written in python flask. It provides developers to access to user, post list and

Engine Bai 157 Nov 11, 2022
Unofficial Python API client for Notion.so

notion-py Unofficial Python 3 client for Notion.so API v3. Object-oriented interface (mapping database tables to Python classes/attributes) Automatic

Jamie Alexandre 3.9k Jan 3, 2023