gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 03:12:14 25 4
gpt4 key购买 nike

我想向 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com