abenassi / google-search-api Goto Github PK
View Code? Open in Web Editor NEWThis project forked from birdapi/google-search-api
Python based api for searching google web, images, calc, and currency conversion.
This project forked from birdapi/google-search-api
Python based api for searching google web, images, calc, and currency conversion.
My server is in Germany, google search api switch to german region everytime, any idea how can I switch to global search?
add suport for python 3
Hi, is there a way to filter results by date in the search output?
santosh@santosh:~/Music/poshaq/data_collection/Google-Search-API$ python sample.py
Traceback (most recent call last):
File "sample.py", line 1, in
from google import google, images
File "/home/santosh/Music/poshaq/data_collection/Google-Search-API/google/init.py", line 2, in
from .modules import calculator, currency, images, utils
File "/home/santosh/Music/poshaq/data_collection/Google-Search-API/google/modules/init.py", line 2, in
from . import calculator
File "/home/santosh/Music/poshaq/data_collection/Google-Search-API/google/modules/calculator.py", line 4, in
from unidecode import unidecode
ImportError: No module named 'unidecode'
i use python3.6 and win10
when i install with pip , occur this error
C:\Users\User\AppData\Local\Programs\Python\Python36\Scripts>pip install Google-Search-API
Collecting Google-Search-API
Using cached Google-Search-API-1.1.13.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\User\AppData\Local\Temp\pip-build-e584nunp\Google-Search-API\setup.py", line 15, in
with open("test_requirements.txt") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test_requirements.txt'
I tried to install the package via pip3
and ran into error. Printing the complete error stack below :
$ pip3 install git+https://github.com/abenassi/Google-Search-API
Collecting git+https://github.com/abenassi/Google-Search-API
Cloning https://github.com/abenassi/Google-Search-API to /tmp/pip-b3gqvjmb-build
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/usr/lib/python3/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2927, in <module>
@_call_aside
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2913, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
add_activation_listener(lambda dist: dist.activate())
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 956, in subscribe
callback(dist)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in <lambda>
add_activation_listener(lambda dist: dist.activate())
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2515, in activate
declare_namespace(pkg)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2097, in declare_namespace
_handle_ns(packageName, path_item)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2046, in _handle_ns
loader.load_module(packageName)
File "./google/__init__.py", line 2, in <module>
from .modules import calculator, currency, images, utils
File "./google/modules/__init__.py", line 2, in <module>
from . import calculator
File "./google/modules/calculator.py", line 4, in <module>
from unidecode import unidecode
ImportError: No module named 'unidecode'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-b3gqvjmb-build/
Any help?
Cannot convert a float to its string representation.
I have this issue:
λ pip install Google-Search-API
Collecting Google-Search-API
Downloading https://files.pythonhosted.org/packages/73/38/eab35d4db8efd12256d30963498afe5210128d3fd221332360de9fc11614/Google-Search-API-1.1.13.tar.gz
Complete output from command python setup.py egg_info:
c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\version.py:1: UserWarning: Module google was already imported from None, but c:\users\alban\appdata\local\temp\pip-install-mn1ginnd\google-search-api is being added to sys.path
import pkg_resources
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\__init__.py", line 12, in <module>
import setuptools.version
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\version.py", line 1, in <module>
import pkg_resources
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 3088, in <module>
@_call_aside
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 3072, in _call_aside
f(*args, **kwargs)
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 3116, in _initialize_master_working_set
for dist in working_set
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 3116, in <genexpr>
for dist in working_set
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2639, in activate
declare_namespace(pkg)
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2176, in declare_namespace
_handle_ns(packageName, path_item)
File "c:\users\alban\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2111, in _handle_ns
loader.load_module(packageName)
File ".\google\__init__.py", line 1, in <module>
from modules import calculator, currency, images, utils
ModuleNotFoundError: No module named 'module
I am using Windows 10 and Anaconda python 3.4 I receive below error while trying to import
>>> from google import google
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\google\__init__.py", line 1, in <module>
from modules import calculator, currency, images, utils
ImportError: No module named 'modules'
Is there a way I can search google news with this repo?
I tried the exactly example and didn't bring me any images on firefox, just opened
Hello
Installing this and using it as "from google import google" causes MANY conflicts with google's cloud API.
May you please consider renaming the library. This is a really nice library but the conflict makes it sadly unusable.
I received this error after doing the following 3 lines:
from google import google
search_results= google.search("something",1)
search_results[0].number_of_results
The last line is the problem. number_of_results seems to be the only problem because a similar line of:
search_results[0].name
gives me the correct result. I was looking in the code and noticed number_of_results gets initialized to None so at the very leased it should return None but instead its saying number_of_results doesn't exist.
Although there's an keyword argument in the function _get_search_url
for No Country Redirection (namely, ncr
) this only allows searching in your own country, or in the US.
@zhiwei1996 added an area
parameter which no longer works, unfortunately (probably due to changes that Google made).
Some changes should be made in order to allow searching from anywhere in the world, regardless of the location. I really don't know if that's possible without a VPN (that's not the fix we're looking for), but maybe messing around with the url get parameters should do it.
You can see more information about this issue here: #38
Hi, sorry if this is the wrong place to ask this, but I keep getting the error:
Error accessing: http://www.google.com/search?nl=en&q=hello&start=0&num=10
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)>
When trying to perform a basic google search using this API.
I've made a Stack Overflow post which hasn't helped so far and I'm not sure what's causing this problem. I assume it must be in the rest of my code. Below is all of my code. Any help is greatly appreciated!
import matplotlib
matplotlib.use('TkAgg') #Stops crashing
from tkinter import *
import sys
sys.path.append('/Users/Cactus/wiki-word-frequency/Google-Search-API')
from google import google
def find_url(search_term):
result = google.search(search_term)
print(result)
if __name__ == "__main__":
def get_text_button(): #On button click
find_url(search.get())
def get_text_enter(search): #On pressing enter/return
find_url(search.widget.get())
root =Tk()
#root.geometry('{}x{}'.format(600, 400))
#Make layout look good when uncommenting the above line
title = Label(root, text="Hello tkinter!")
title.grid(column=0, row=0, columnspan=2)
label = Label(root, text="Search term: ")
label.grid(column=0, row=1)
search = Entry(root, bd=3)
search.bind("<Return>", get_text_enter)
search.grid(column=1, row=1)
button = Button(root, text="Submit", command=get_text_button)
button.grid(column=1, row=2, columnspan=1)
exit = Button(root, text="Exit", command=root.destroy)
exit.grid(column=0, row=2, columnspan=1)
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.mainloop()
Hi,
I tryed to install it mutiple times, manually, by pip nothing suits for me.
The following error is produced:
File "C:\Python27\lib\site-packages\google__init__.py", line 2, in
from modules import standard_search, shopping_search
ImportError: No module named modules
`HTTP Error 503: Service Unavailable
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\google\modules\utils.py", line 432, in get_html
html = urllib.request.urlopen(request).read()
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 564, in error
result = self._call_chain(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 756, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 564, in error
result = self._call_chain(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
/ File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 756, in http_error_302
Googling and searching Wikipedia return self.parent.open(new, timeout=req.timeout)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Service Unavailable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "something.py", line 326, in
function()
File "something.py", line 287, in get_points_sample
x, y= google_wiki(a, b, c)
File "something.py", line 253, in google_wiki
search_wiki = google.search(o, num_pages)
File "C:\ProgramData\Anaconda3\lib\site-packages\google\modules\standard_search.py", line 69, in search
html = get_html(url)
File "C:\ProgramData\Anaconda3\lib\site-packages\google\modules\utils.py", line 437, in get_html
if e.code == 503 and 'CaptchaRedirect' in e.read():
TypeError: a bytes-like object is required, not 'str'`
Hello,
I'm having trouble installing this package. I use the comand:
pip install Google-Search-API (Edit : I used sudo with no success)
but get the following error
"Command "python setup.py egg_info" failed with error code 1 in..."
I have tried
pip install --upgrade setuptools
pip install ez_setup
easy_install -U setuptools
without success. Can anyone help me on this issue?
python
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import urllib.request
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named request
https://github.com/abenassi/Google-Search-API/blob/master/google/modules/utils.py#L11
Reference: https://stackoverflow.com/questions/36080548/can-not-solve-importerror-no-module-named-request
Hello,
I'm having trouble installing this package. I use the comand:
pip install Google-Search-API
but get the following error
"Command "python setup.py egg_info" failed with error code 1 in..."
I have tried
pip install --upgrade setuptools
pip install ez_setup
easy_install -U setuptools
without success. Can anyone help me on this issue?
How do you print the results of search_results
as shown in the example?
Due to Python 2 retiring in a year (https://pythonclock.org/), I would suggest to update this library to Python 3 so people can still use this in the future. If you have already created a Python3 version of this, please do add it in pip3 because it doesn't seem to work when I tried downloading it.
Error :
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dyjn_np3/Google-Search-API/
Thank you for your time
What is the solution to this error?
I got really confused, because none of the solutions I could find out there work for me. I am running 3.6 version.
When I run this code:
from google import google
results = google.search_images("banana")
An IndexError: list index out of range
occurred.
This bug is caused by images.py
, line 298-309
, function _get_file_name(link)
def _get_file_name(link):
temp_name = link.rsplit('/', 1)[1]
image_format = _parse_image_format(link)
if image_format and temp_name.rsplit(".", 1)[1] != image_format:
file_name = temp_name.rsplit(".", 1)[0] + "." + image_format
else:
file_name = temp_name
return file_name
For the "banana" image search, the problem is cause by this link: http://vignette2.wikia.nocookie.net/donkeykong/images/1/17/BananaDKCR.png/revision/20110926232526
Given
link = "http://vignette2.wikia.nocookie.net/donkeykong/images/1/17/BananaDKCR.png/revision/20110926232526"
in _get_file_name(link)
, we have
temp_name = "20110926232526"
image_format = "png"
Since temp_name
has no .
, temp_name.rsplit(".", 1)
is a list of length 1 and temp_name.rsplit(".", 1)[1]
doesn't exist.
I think it's better to change temp_name.rsplit(".", 1)[1]
to temp_name.rsplit(".", 1)[-1]
, which will solve this problem.
hey, I just installed your library for python3 and pyhton2 using pip.. on python3 pip failed since the requirements selenium unidecode and something else were not met. In pip2 they got installed smoothly. Maybe you have to patch the dependencies for pip3 ?
Sometimes, google will show results even when some keywords are missing. Is there a way to show such information in the search results?
from google import google
num_page = 1
search_results = google.search('Robert V Martinez thermogenesis', num_page)
In the above, https://en.wikipedia.org/wiki/Bob_Martinez will be returned but thermogenesis
is shown as missing.
In [4]: search_results = google.search('Inflianskas')
In [5]: s = search_results[0]
In [6]: s.name
Out[6]: 'Roman.Inflianskas · PyPIhttps://pypi.org/user/Roman.Inflianskas/'
In [7]: s
Out[7]:
GoogleResult(name=Roman.Inflianskas * PyPIhttps://pypi.org/user/Roman.Inf..
description=profanity-filter. Last released on Nov 25, 2018. ..
Now is not mocking the html, it is launching the request to the internet. It should be mocking it.
Hello. Could you add support python 3?
I don't want google to detect this system as bot. so what can i do. I want to perform 100 of pages to be redirected without getting ban. Time doesn't matter.
I want to get search results page by page. Now it's not possible.
Is there a limit to do requests? I called the search routine many times and now I got his error message:
urllib.error.HTTPError:
HTTP Error 503: Service Unavailable
Hey abenassi,
I tried your code and I'm very happy with it.
I only have the issue, that each google request takes at minimum 3s.
I'm using the function as follows:
import urllib.request as urllib2
from google import google
num_pages =1
Google_result = google.search(query, num_pages, lang = 'de', area = 'de')
I would be very happy if you could help me.
Best regards,
SearchPirat
Hi,
I am trying to add the package to a .yml file to standardise work accross different machines. I have configured it on my requirements.txt
file, however pip is not able to satisfy the requirement Google-Search-API>=1.1.14
as the version is not available on pip. See link to Pypi.org (https://pypi.org/project/Google-Search-API/#history).
What would be the easiest way of either:
Thanks in advance
Hi, I just ran a simple script:
from google import google num_page = 3 search_results = google.search("Hello World", num_page)
It is giving an error even though I have installed the library through pip.
Error:
File "", line 1, in
File "google.py", line 1, in
from google import google
ImportError: cannot import name google
What should I do to correct it?
Previous GET link used to be something like this:
https://www.google.com/search?hl=es&output=search&tbm=shop&q=apple&oq=apple
But now there's a strange parameter gs_l added to the link that makes it like this:
https://www.google.com/search?hl=es&output=search&tbm=shop&q=apple&oq=apple&gs_l=products-cc.3...2975.3545.0.3699.5.5.0.0.0.0.0.0..0.0....0...1ac.1.64.products-cc..5.0.0.6_vXTCVsw9s
To fix this, a way to reproduce this new parameter should be found.
https://github.com/audreyr/cookiecutter-pypackage
Specially:
Is it possible to search via Google's built-in filters, like "site:" or date range (shown under Tools->Any Time->Custom range...", which populates cd_min and cd_max URL parameters)?
After less than 500 requests, I think Google banned the hard-coded useragent. Is it possible to let users specify useragent in google.search?
It took me a few minutes to figure out that selenium driver is used for image search and the driver expects a firefox binary to be installed on my system. Simply downloading firefox fixed it for me, so it should be mentioned in README
It seems that the script doesn't wait enough time or attempts to reload the same page all the time (not changing to the next page).
import os, sys
import json
import requests
from pprint import pprint
from google import google, images
options = images.ImageOptions()
options.image_type = images.ImageType.CLIPART
options.larger_than = images.LargerThan.MP_4
options.color = "green"
results = google.search_images("banana", options)
pprint(results)
on running the script, i got
Traceback (most recent call last):
File "main.py", line 18, in <module>
results = google.search_images("banana", options)
File "/home/muhammadtaqi/code/arslan/venv/local/lib/python2.7/site-packages/google/modules/images.py", line 430, in search
browser = get_browser_with_url("")
File "/home/muhammadtaqi/code/arslan/venv/local/lib/python2.7/site-packages/google/modules/utils.py", line 83, in get_browser_with_url
browser.set_page_load_timeout(timeout)
File "/home/muhammadtaqi/code/arslan/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 818, in set_page_load_timeout
'type': 'page load'})
File "/home/muhammadtaqi/code/arslan/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/home/muhammadtaqi/code/arslan/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: timeouts
I have firefox and selenium driver install too.
Hi,
Search works first times and after a while gives error accessing for all pages.
Is there a limit?
\ty
The script should stop when google doesn't allow to do more queries.
Traceback (most recent call last): File "testgoogle.py", line 1, in <module> from google import google ModuleNotFoundError: No module named 'google'
All successfully installed but still seem to get this error. Is anyone able to help?
I ran Google Image API code and received "ImportError: cannot import name images" error.
from google import google, images
options = images.ImageOptions()
options.image_type = images.ImageType.CLIPART
options.larger_than = images.LargerThan.XGA
results = google.search_images("bodycon dress", options)
euros = google.convert_currency(5.0, "USD", "EUR")
rate = _parse_currency_response(response, to_currency)
File "/Library/Python/2.7/site-packages/google/modules/currency.py", line 51, in _parse_currency_response
str_rate = bs.find(id="currency_converter_result").span.get_text()
AttributeError: 'NoneType' object has no attribute 'get_text'
perhaps nothing returned
I tried the following example code:
from google import google
num_page = 3
search_results = google.search("This is my query", num_page)
However, the search_results is a empty list. Is google changing the way their page structures to disable any web scrawling?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.