googlesearch icon indicating copy to clipboard operation
googlesearch copied to clipboard

a search gives no result, no error, nothing

Open sanderjo opened this issue 3 years ago • 11 comments

  • google-search version: from pypi. There is no googlesearch.__version__, but install says google-search-1.1.1
  • Python version: 3.8.5
  • Operating System: Ubuntu 20.04

Description

Simple search. I get no results, no errors, and nothing.

What I Did


sander@brixit:~$ python3 -m pip install google-search
Collecting google-search
  Downloading google_search-1.1.1-py2.py3-none-any.whl (6.5 kB)
Requirement already satisfied: soupsieve in ./.local/lib/python3.8/site-packages (from google-search) (2.2.1)
Requirement already satisfied: lxml in ./.local/lib/python3.8/site-packages (from google-search) (4.6.2)
Requirement already satisfied: beautifulsoup4 in ./.local/lib/python3.8/site-packages (from google-search) (4.9.3)
Installing collected packages: google-search
Successfully installed google-search-1.1.1


sander@brixit:~$ python3
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from googlesearch.googlesearch import GoogleSearch
>>> response = GoogleSearch().search("something")
>>> response.results
[]
>>> 


Other machine same same:

>>> from googlesearch.googlesearch import GoogleSearch
>>> response = GoogleSearch().search("something")
>>> print(response.results)
[]
>>> response.
response.results  response.total    
>>> response.total
4
>>> 

Am I doing something wrong?

sanderjo avatar May 08 '21 18:05 sanderjo

I get the same problem

kenuxi avatar May 21 '21 07:05 kenuxi

Same here. Can anyone help me?

BisratGetnet avatar Jun 04 '21 07:06 BisratGetnet

I think it's because the selector is not working So we can just wait until it gets fixed

DerSchinken avatar Jun 16 '21 13:06 DerSchinken

Same here

SillyGithub5 avatar Jul 01 '21 15:07 SillyGithub5

I fixed the problem, by change RESULT_SELECTOR = "div.g" to RESULT_SELECTOR = "div.g>div>div" (Update!) NEW SOLUTION HERE: https://github.com/anthonyhseb/googlesearch/issues/75#issuecomment-876229778

https://github.com/anthonyhseb/googlesearch/blob/e2d3e74a89151bdbe6529400291f72369aa1bcc5/googlesearch/googlesearch.py#L24

and then, replace code line 70 with selector = GoogleSearch.RESULT_SELECTOR or just delete it and change soup.select() argument (line 71) with self.RESULT_SELECTOR

https://github.com/anthonyhseb/googlesearch/blob/e2d3e74a89151bdbe6529400291f72369aa1bcc5/googlesearch/googlesearch.py#L70-L71

Here my output output

afifabroory avatar Jul 03 '21 14:07 afifabroory

self.RESULT_SELECTOR

KeyError: 'href' when trying your fix

BisratGetnet avatar Jul 07 '21 18:07 BisratGetnet

@BisratGetnet I have new solution here

Change RESULT_SELECTOR to:

RESULT_SELECTOR = "div.g>div>div.tF2Cxc"

Here my output, for my new solution results2 it's remove duplicate result (you can compare with my previous screenshot)

afifabroory avatar Jul 08 '21 08:07 afifabroory

@BisratGetnet I have new solution here

Change RESULT_SELECTOR to:

RESULT_SELECTOR = "div.g>div>div.tF2Cxc"

Here my output, for my new solution results2 it's remove duplicate result (you can compare with my previous screenshot)

Thanks for replaying but still same error i think it's because google user different selector in different countries can you show me how to take a selector based on google search results.

BisratGetnet avatar Jul 11 '21 08:07 BisratGetnet

Thanks for replaying but still same error i think it's because google user different selector in different countries can you show me how to take a selector based on google search results.

Ah... okay.

You need to open Inspect on your browser, and then select element that you want to scrape, after that right click element and then copy Selector/CSS Selector. Alternatively you can find element manually.

To test whether the element being searched for is correct, you can test using method querySelectorAll or querySelector on your Console.

for example:

document.querySelectorAll('div.g>div>div.tF2Cxc');

Here's reference for CSS Selector: https://www.w3schools.com/cssref/css_selectors.asp

Sorry if my explanation is not detailed enough or makes you confused because of my English 🙈, hope it helps you.

afifabroory avatar Jul 11 '21 10:07 afifabroory

I only got "HTTPError: Too Many Requests", anyone can help?

frankiejou avatar Aug 04 '21 01:08 frankiejou

just use 'googlesearch' liberary by author = 'Anime no Sekai' copyright = 'Copyright 2021, googlesearch' credits = ['animenosekai'] license = 'MIT License' version = 'googlesearch v1.1.1' maintainer = 'Anime no Sekai' email = '[email protected]' status = 'Stable'

it works fine for me

BisratGetnet avatar Aug 06 '21 11:08 BisratGetnet