Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从python中的google搜索中排除某些网站?_Python_Google Search Api - Fatal编程技术网

如何从python中的google搜索中排除某些网站?

如何从python中的google搜索中排除某些网站?,python,google-search-api,Python,Google Search Api,我使用的是Mario Vilas的谷歌搜索API,可以在github上找到: 现在,在搜索过程中,我想从显示中删除某些站点。我已经阅读了文档,似乎没有任何东西允许我们排除某些域。这方面有什么办法吗?如果不是的话,你知道有没有其他谷歌搜索API可以做到这一点 这是我的密码: keyword = input("Keyword: ") country = input("Country:") tld_of_country = domain_names[country] for website in

我使用的是Mario Vilas的谷歌搜索API,可以在github上找到:

现在,在搜索过程中,我想从显示中删除某些站点。我已经阅读了文档,似乎没有任何东西允许我们排除某些域。这方面有什么办法吗?如果不是的话,你知道有没有其他谷歌搜索API可以做到这一点

这是我的密码:

keyword = input("Keyword: ")
country = input("Country:")
tld_of_country = domain_names[country]



for website in search(keyword, tld=tld_of_country, num=2, 
stop=2, country="canada", pause=2): 
 try:
      links.append(website)
 except:
      continue

搜索查询长度有限,因此如果使用以下方法排除太多域: “-website:site”,谷歌不会返回任何结果。在这种情况下,您可以使用正则表达式或类似的方法手动从列表中排除。您可以使用:

[x for x in yourlist if "domain" not in x]

或者,在您的情况下,您可以在附加过程之前添加if语句。

-site:domain
在搜索字符串中,我是否将其放在关键字参数中?我也喜欢很多被列入黑名单的网站。我们可以像列表那样做吗?我不确定这个googlesearch包是如何将关键字映射到最终请求的,但看看这个示例搜索,这是标准的GoogleFu