Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Google api Google自定义搜索json api优化标签_Google Api - Fatal编程技术网

Google api Google自定义搜索json api优化标签

Google api Google自定义搜索json api优化标签,google-api,Google Api,我正在使用google自定义json/RESTAPI构建一个站点搜索,但我不确定如何获得“方面/细化标签”来过滤结果 它们以json的形式返回,但我在文档中没有看到任何解释如何使用它进行过滤的内容 要使用facet进行过滤,q参数的值应如下所示: text_to_search more:facet_name params = { "q" : "bicycles more:race_bicycles", "cx": cx, "key": key, } page

我正在使用google自定义json/RESTAPI构建一个站点搜索,但我不确定如何获得“方面/细化标签”来过滤结果


它们以json的形式返回,但我在文档中没有看到任何解释如何使用它进行过滤的内容

要使用facet进行过滤,q参数的值应如下所示:

text_to_search more:facet_name
params = {
    "q" : "bicycles more:race_bicycles",
    "cx": cx,
    "key": key,
    }

page = requests.request("GET", url = "https://www.googleapis.com/customsearch/v1" , params=params)

results = json.loads(page.text)
完成自定义搜索后,必须将方面名称添加到搜索查询中以“激活”过滤器。您的方面名称将被命名为与您命名的优化标签相同的名称。如果您将优化标签命名为“race bicycles”,则需要将
更多:race_bicycles
添加到查询中。您还可以在
label_with_op
中的请求列表中找到您的方面名称。只需复制并在查询中使用_op标记_

对于在python中使用api,请求如下所示:

text_to_search more:facet_name
params = {
    "q" : "bicycles more:race_bicycles",
    "cx": cx,
    "key": key,
    }

page = requests.request("GET", url = "https://www.googleapis.com/customsearch/v1" , params=params)

results = json.loads(page.text)