我正在使用 Google 自定义搜索为我的网站上的内容编制索引。
当我使用 REST 客户端发出 get 请求时
https://www.googleapis.com/customsearch/v1?key=xxx&q=query&cx=xx
我在亚秒内得到回复。
但是当我尝试使用我的代码拨打电话时,需要花费六秒钟的时间。我究竟做错了什么 ?
__author__ = 'xxxx'
import urllib2
import logging
import gzip
from cfc.apikey.googleapi import get_api_key
from cfc.url.processor import set_query_parameter
from StringIO import StringIO
CX = 'xxx:xxx'
URL = "https://www.googleapis.com/customsearch/v1?key=%s&cx=%s&q=sd&fields=kind,items(title)" % (get_api_key(), CX)
def get_results(query):
url = set_query_parameter(URL, 'q', query)
request = urllib2.Request(url)
request.add_header('Accept-encoding', 'gzip')
request.add_header('User-Agent','cfc xxxx (gzip)')
response = urllib2.urlopen(request)
if response.info().get('Content-Encoding') == 'gzip':
buf = StringIO(response.read())
f = gzip.GzipFile(fileobj=buf)
data = f.read()
return data
Run Code Online (Sandbox Code Playgroud)
我已经实现了性能提示中提到的性能提示。我将不胜感激任何帮助。谢谢。
我一直在尝试为在 Google 自定义搜索上获得的结果设置一个日期范围,但还不知道如何设置。到目前为止,我的网址如下所示:
https://www.googleapis.com/customsearch/v1?key=MY_KEY&cx=MY_OTHER_KEY&q=bigdata&alt=json&fields=queries(request,nextPage),items(title,link,snippet)&cr=&start=1
Run Code Online (Sandbox Code Playgroud)
例如,我试图获取 01/01/2014 到 02/01/2014 范围内的结果。有什么办法可以做到吗?
我正在创建一种 BOT。我想向我的机器人添加网络搜索功能。即,如果您这么说,我希望我的机器人在网络上搜索用户。
为了实现这一点,我正在考虑使用 GOOGLE 搜索引擎。但在其自定义搜索 API的概述页面上,它说
创建可在指定的网站或页面集合中进行搜索的自定义搜索引擎。
有什么方法可以让这个指定的集合默认为整个网络。或者还有其他方法可以解决这个问题吗?
当在 docker swarm 服务中使用 Go 程序时,stream ID 1; PROTOCOL_ERROR当我调用 a client.Get(url)) 时,我会得到 400 状态和错误消息,当我调用 ) 时,我会得到 200 状态和结果go run *.go。我在 Mozilla 的容器内使用“CA 根证书捆绑包”。任何帮助表示赞赏。我的代码如下。
client := &http.Client{Timeout: 30 * time.Second, Transport: &http.Transport{
DisableCompression: true,
DisableKeepAlives: true,
}}
r, err := client.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
fmt.Println(url, err) // The Google Search url and err: stream error: stream ID 1; PROTOCOL_ERROR
return …Run Code Online (Sandbox Code Playgroud) 我有谷歌自定义搜索,默认搜索框有背景图像,我可以删除该图像,但无法替换我的图像.有没有办法做到这一点.
我正在尝试修改一些使用Google API的java代码.我无法获得的功能之一是dateRestrict.有关这方面的信息可以在这里找到: GoogleAPI
为了实现这一点,我在查询后附加以下字符串.它与完整URL正确连接,因为其他参数可以使用它.
String parameters = "&dateRestrict=2012-01-01";
我也尝试过1d和1m,但这些都不能作为参数
如果有人能告诉我dateRestrict的一个例子,我会非常感激.我只是不明白他们在API中使用它的意思.谢谢.
我在python中使用google image api下载20个第一个图像结果,代码如下:
import os
import sys
import time
from urllib import FancyURLopener
import urllib2
import simplejson
searchTerm = "Cat"
# Replace spaces ' ' in search term for '%20' in order to comply with request
searchTerm = searchTerm.replace(' ','%20')
# Start FancyURLopener with defined version
class MyOpener(FancyURLopener):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
myopener = MyOpener()
# Set count to 0
count=0
for i in range(0,4):
# Notice that the start changes for …Run Code Online (Sandbox Code Playgroud) 在尝试访问Google自定义搜索引擎API时,我收到超出每日限制错误消息403.根据官方文档:https://developers.google.com/custom-search/json-api/v1/overview我每天获得10k次查询.而且我很确定今天我已经在2k以下查询了.我已启用结算并输入了信用卡信息(我的帐户也有).
我有两个问题:
我已经看到了其他类似的问题,我发布了这个问题,因为它们似乎都没有解决我的问题.
我使用以下代码添加了Google自定义搜索引擎.
(function() {
var cx = '005899633628958982661:wekn1lpckzg';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
Run Code Online (Sandbox Code Playgroud)
现在我的网站有一个可用的搜索框,唯一的问题是我无法在搜索文本框中使用占位符.
我也尝试过代码
$('input.gsc-input').attr('placeholder', 'custom text here');
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
在实施Google自定义搜索引擎(CSE)并将其JavaScript代码添加到我的网站的母版页后,我看到了搜索框和按钮,但按钮上没有文字或图片.它只是一个空白的灰色条,如下所示.

灰色按钮应该有一个放大镜的图像.这是Google提供的JavaScript代码,因此在我看来,所有可以更改的内容都是:
<script>
(function () {
var cx = 'XXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXX';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/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)
我尝试为gcse元素添加内联样式以增加高度,但这没有帮助.
css ×2
google-api ×2
jquery ×2
date-range ×1
docker ×1
go ×1
java ×1
json ×1
php ×1
placeholder ×1
python ×1
search-box ×1