向 python 中的 Google 个输入工具发送请求

Send request to Google input tools in python

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

["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')