如何在google自定义搜索API中的siteSearch上指定多个值?

问题描述 投票:6回答:3

我正在使用谷歌自定义搜索API并希望使用siteSearch创建搜索:

https://www.googleapis.com/customsearch/v1?key=k&cx=cx&q=cocos2d&siteSearch=www.cocos2d-iphone.org&siteSearchFilter=i

and it works fine (returns all the result only from the given site).

Then I want to specify TWO sites to search so I tried to change the :
siteSearch=www.cocos2d-iphone.org

to 
siteSearch=www.cocos2d-iphone.org www.XXXXXXXX.org
siteSearch=www.cocos2d-iphone.org|www.XXXXXXXX.org
siteSearch=www.cocos2d-iphone.org||www.XXXXXXXX.org

but none of these works.

hope someone can help here, thanks:)
google-custom-search
3个回答
4
投票

目前我不相信您可以通过查询参数siteSearch指定更多网站。

尽管如此,您可以在此处配置自定义搜索引擎:https://www.google.com/cse/manage/all在“要搜索的站点”区域中。

这也适用于排除,你可以在这里阅读:https://support.google.com/customsearch/bin/answer.py?hl=en&answer=2631038&topic=2601037&ctx=topic


0
投票

您不能使用as_sitesearch参数执行此操作,因为它只接受单个值。但是你可以使用as_q参数实现你想要的效果,将它设置为某个值,如:“site:google.com或site:microsoft.com” - 这将以与this search类似的方式工作。

as_q参数记录为here

as_q参数提供要在文档中检查的搜索项。此参数还常用于允许用户指定要在一组搜索结果中搜索的其他术语。示例q = president&as_q = John + Adams


-1
投票

使用“space”作为分隔符

下面是适用于我的示例PHP代码

$url="https://www.googleapis.com/customsearch/v1?key=k&cx=cx&q=cocos2d&siteSearch=".urlencode("www.cocos2d-iphone.org www.XXXXXXXX.org")."&siteSearchFilter=i"

谢谢,OJL Suthar

© www.soinside.com 2019 - 2024. All rights reserved.