我正在使用Mario Vilas的Google搜索API,可以在github上找到:https://github.com/MarioVilas/googlesearch
现在,在搜索过程中,我想删除某些网站,使其不再显示。我已经阅读了文档,似乎没有什么可以让我们排除某些域。有什么解决办法吗?如果不是,您是否知道其他任何可能会解决问题的Google搜索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
https://support.google.com/gsa/answer/2672318?hl=en
搜索查询的长度是有限的,因此,如果您使用排除了太多的域,则:“ -website:site”,Google不会返回任何结果。在这种情况下,您可以使用RegEx或类似方法从列表中手动排除。您可以使用:
[x for x in yourlist if "domain" not in x]