Sensei
Sensei

Reputation: 15

How do I exclude search results in Python

I am using the following library to extract google search urls:

from googlesearch import search

This is the function that performs the google search:

search(query, tld='com', lang='en', num=10, start=0, stop=None, pause=2.0)

My question is: How do I use this function to exclude certain domains in my search results?

Upvotes: 1

Views: 547

Answers (1)

Serge
Serge

Reputation: 3775

If you want use search interface to exclude a domain, add an argument

 extra_params={'-site' : 'youtube.com'}

e.g.

  search(query,
      tld='com',
      lang='en',
      num=10,
      start=0,
      stop=None,
      pause=2.0,
      extra_params={'-site' : 'youtube.com'}
  )

Alternatively, you can just append -site:youtube.com or whatever needed into your query.

Upvotes: 2

Related Questions