pan*_*kaj 6 google-search-api google-custom-search google-oauth
我们希望使用Google自定义搜索来实施Google附加链接搜索框.在Google 文档中,我发现我们需要包含以下代码才能启用附加链接搜索框
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://www.example-petstore.com/",
"potentialAction": {
"@type": "SearchAction",
"target": "https://query.example-petstore.com/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是我们仍然停留在上述属性中的"目标"节点.由于我们没有自己的搜索页面,我们希望使用Google自定义搜索,因此我应该在这个"目标"节点中填写什么值.
我们已经为我们的网站创建了一个Google自定义搜索引擎.并在下面找到代码
<script>
(function() {
var cx = 'CX_ID';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
Run Code Online (Sandbox Code Playgroud)

请建议,如何在附加链接搜索框代码中指向Google自定义搜索.
谢谢
唯一的解决办法:
为此,您需要在自己的网站上有一个搜索页面。
对于“target”参数,在您的网站上进行搜索并获取该 URL,并将用于搜索的搜索词替换为“{search_term_string}”
如果您在网站上创建一个使用自定义 Google 搜索的搜索页面,您应该能够获取该target- 属性的链接。
原因是Google不提供搜索功能
会将用户直接引导至您网站自己的搜索页面。
资料来源:
| 归档时间: |
|
| 查看次数: |
1652 次 |
| 最近记录: |