python - 在Python中向Google输入工具发送请求

标签 python google-api google-input-tools

我想向 Google 输入 API 发送一些(大约 200k)请求并显示结果。例如,我想发送deep并且它必须返回:

["deep","dépenses","dépend","dépendance","dépendant"]

我尝试了以下脚本,但没有帮助:

def request(word):
    url = 'https://inputtools.google.com/request?text=' + word + '&itc=fr-t-i0-und&num=5&cp=0&cs=1&ie=utf-8&oe=utf-8&app=test'
    conn = http.client.HTTPConnection(url)
    res = conn.getresponse()
    print(res.status, res.reason)

我想知道如何才能实现这一点? (参见我想要实现的示例 here )

最佳答案

我不确定你从哪里得到你的调用语法,但如果你 read the documentation ,您会发现您需要将代码编写为

import http.client
def request(word):
    conn = http.client.HTTPSConnection('inputtools.google.com')
    conn.request('GET', '/request?text=' + word + '&itc=fr-t-i0-und&num=5&cp=0&cs=1&ie=utf-8&oe=utf-8&app=test')
    res = conn.getresponse()
    print(res.status, res.reason)
    print(res.read())

request(word='deep')

关于python - 在Python中向Google输入工具发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42770790/

相关文章:

youtube - 我可以分享多少个用户 youtube 私有(private)视频?

java - YouTube数据API-HTTP/1.1 401未经授权

youtube - 用于预验证的 Google/Youtube API 服务器 key 格式

algorithm - 实现音译和音译建议的标准算法

android - 将 Google 手写输入键盘直接集成到您的 Android 应用程序中

Python 提高函数速度

python - 如何只为pandas中IsB列不为空的记录设置IsA?

python - 从变量取消引用内存中的 Python 列表对象时会发生什么?

python - 在python中计算范围内的用户输入数字

java - 使用 java 更改/切换 Windows 7 输入语言