Package: python-googlesearch
googlesearchgooglesearchlets you use Google Searching capabilities right from your Python code or from your CLIMake any Google Search right from Python!Getting StartedThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.PrerequisitesYou will need Python 3 to use this module# vermin outputMinimumrequiredversions:3.2
Incompatibleversions:2According to Vermin, Python 3.2 is neededAlways check if your Python version works withgooglesearchbefore using it in productionInstallingOption 1: From PyPIpipinstallpython-googlesearchMake sure to downloadpython-googlesearchasgooglesearchcannot be given to any package on PyPIEven if you downloadpython-googlesearch,googlesearchis used for the imports and the CLI version for conveniency purposesOption 2: From Gitpipinstallgit+https://github.com/Animenosekai/googlesearchYou can check if you successfully installed it by printing out its version:$python-c"import googlesearch; print(googlesearch.__version__)"# output:googlesearchv1.1.1or just:$googlesearch--version# output:googlesearchv1.1.1UsageYou can use googlesearch in Python by importing it in your script:>>>fromgooglesearchimportSearch>>>python_results=Search("Python")>>>python_results.results[<SearchResulttitle="Python.org"(www.python.org)>,<SearchResulttitle="Python"()>,<SearchResulttitle="Python (langage) — Wikipédia"(fr.wikipedia.org›wiki›Python_(langage))>,...]CLI usageYou can use googlesearch in other apps by accessing it through the CLI version:$googlesearch--queryPython{"query":"Python","results":[{"url":"https://www.python.org/","title":"Welcome to Python.org","displayedURL":"www.python.org","description":"The official home of the Python Programming Language.\nDownloads \u00b7 Python For Beginners \u00b7 Quotes about Python \u00b7 Python Essays"},[...]],"relatedSearches":["Python serpent","Python openclassroom",[...]],"success":true}Interactive Shell (REPL)An interactive version of the CLI is also available$googlesearch
Enter'.quit'toexitgooglesearch[?](googlesearch~Query)>:...# enter your query[?]Whatdoyouwanttodo?:# select the result with your keyboard's arrows and [enter]—————————————————SEARCHRESULT—————————————————[...]# site's nameDescription:# the site's descriptionURL:...# site's URLRelatedSearches:# a max of 3 related searchesYou can get help on this version by using:$googlesearch--help
usage:googlesearch[-h][--version][--queryQUERY][--langua...As a Python moduleSearchThe search class represents a Google Search.It lets you retrieve the different results/websites (Search.results) and the related searches (Search.related_searches)How to useThis class is lazy loading the results.When you initialize it withSearch(), it takes aqueryas the required parameter and the following parameters as optional parameters:language: The language to request the results in (All of the website won't be in the given language as it is biased by lots of factors, including your IP address location). This needs to be a two-letter ISO 639-1 language code (default: "en")number_of_results: The max number of results to be passed to Google Search while requesting the results (This won't give you theexactnumber of results) (default: 10)retry_count: A positive integer representing the number of retries done before raising an exception (useful asgooglesearchseems to fail sometimes) (default: 3)parser: The BeautifulSoup parser to use (default: "html.parser")It will only load and parse the website whenresultsorrelated_searchesis called.parseris theBeautifulSoupparser used to parse the website and .resultsis a list ofgooglesearch.models.SearchResultElement.related_searchesis a list ofSearchelements.SearchResultElementThis class represents a result and is initialized bygooglesearch.It holds the following information:url: The URL of the websitetitle: The title of the websitedisplayed_url: The URL displayed on Google Searchdescription: The description of the websiteExtraEvery class has theas_dictfunction which converts the object into a dictionary. ForSearch, the as_dict function will convert the otherSearchobjects inrelated_searchto a string with the query.ExceptionsAll of the exceptions inherit from theGoogleSearchExceptionexception.You can find a list of exceptions in theexceptions.pyfileDeploymentThis module is currently in development and might contain bugs.Feel free to use it in production if you feel like it is suitable for your production even if you may encounter issues.Built Withbeautifulsoup4- To parse the HTMLrequests- To make HTTP requestspyuseragents- To create theUser-AgentHTTP headerinquirer- To make a beautiful CLI interfaceAuthorsAnime no Sekai-Initial work-AnimenosekaiLicenseThis project is licensed under the MIT License - see theLICENSEfile for more details