googlesearch icon indicating copy to clipboard operation
googlesearch copied to clipboard

Sometimes returns the href of the search query as a result

Open Themis3000 opened this issue 2 years ago • 2 comments

the following bit of code prints out the search query as a result for me:

from googlesearch import search

se = search("Google",num_results=10,lang="en")

print(se[-1])

here's what the output of the script looks like : /search?q=Google&num=11&hl=en&tbm=isch&source=iu&ictx=1&fir=mM5eejaz-bUIsM%252C0UCf55-GTy6fDM%252C%252Fm%252F045c7b&vet=1&usg=AI4_-kS3fhB6I4-4YGkbI-0POxk60cjoEw&sa=X&ved=2ahUKEwi8y-PKyuzzAhVRZc0KHSjABlkQ_B16BAhIEAI#imgrc=mM5eejaz-bUIsM

It seems like this is happening because of the descriptive result with more information that comes up on the right side. The package tries to process it like any other result and ends up selecting an element with no href value and tried to get the href value. The default action of BeautifulSoup is just to return the pages href value it seems and so that's how it end up at the back of the results.

Themis3000 avatar Oct 28 '21 07:10 Themis3000

upon reviewing the code, it looks like this issue would be solved with pull request #3 due to it validating that it's returning links before returning them.

Themis3000 avatar Oct 29 '21 01:10 Themis3000

interesting, when I make my update I'll make sure to do that

Nv7-GitHub avatar Oct 29 '21 03:10 Nv7-GitHub