用python向Google输入工具发送请求

2024-06-28 11:35:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我试着按照脚本来做,但没用:

^{pr2}$

我想知道怎样才能做到这一点?(请参阅我想要实现的示例here


Tags: 脚本api示例inputheregoogle请参阅deep
1条回答
网友
1楼 · 发布于 2024-06-28 11:35:21

我不确定您的调用语法是从哪里得到的,但是如果您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')

相关问题 更多 >