https - 从对 translate.google.com 的 https 请求中未收到任何翻译文本
问题描述
现在,我尝试通过 Roblox Studio 使用 Https 服务,通过向 translate.google.com 链接发送请求来像翻译一样,事情是我得到的任何回报都不会给我翻译的文本。
我将收到的内容放在谷歌文档中,并试图通过按 ctrl + f 来找到它,但没有运气,我唯一能找到的是应该翻译的文本。这是代码,以防您想亲自尝试,但我警告您,运行此代码可能会使 Roblox 有一段时间没有响应,因为他们返回的信息很多。
不知道是不是我做错了,求大神帮忙!我只是想让它告诉我法语的“Hello world”是什么,也没有错误消息。
local http = game:GetService("HttpService")
local Message = "Hello world"
http:UrlEncode(Message) -- 'Hello world' -> 'Hello%20world'
local response = http:RequestAsync(
{
Url = "https://translate.google.com/?sl=en&tl=fr&text=" .. Message .. "!&op=translate";
Method = "GET"
}
)
if response.Success then
print(response.StatusMessage)
print(response.StatusCode)
print(response.Body)
--print(response.Headers)
else
print("The request failed: ", response.StatusCode, response.StatusMessage)
end
解决方案
在浏览器(例如)上访问 urlhttps://translate.google.com/?sl=en&tl=fr&text=Hello%20World!&op=translate
时,您看到的翻译是使用加载页面后浏览器执行的 Javascript 代码获取的。
浏览器检索页面的 html 正文(就像您在代码中所做的那样),然后在 html 正文中执行 javascript 检索翻译并更新页面。
除非您使用像 Selenium 这样的浏览器驱动程序,否则我看不到您如何以简单的方式做您想做的事。
另外,我确信谷歌对自动机器人有一些保护,所以在请求过多之后,你的程序可能会被 ReCaptcha 阻止。
翻译文本的正确方法是使用Google Cloud Translate API,我认为它每月最多可以免费处理 500k 个请求。还有来自微软的Azure Translator,它也有一个免费层。
推荐阅读
- django - Django用户模型在被覆盖后不起作用
- android - 为什么子组件不能与匕首中的父组件具有相同的范围
- node.js - Node.js - SyntaxError: Unexpected token * when import express
- r - 用 R 向量化我的函数不起作用
- kubernetes - Kubernetes NFS PV,锁定问题
- google-colaboratory - 没有注册 OpKernel 以支持节点 TPUReplicateMetadata 使用的 Op 'TPUReplicateMetadata'
- html - 如何让我的侧边栏与页面右侧的文本对齐?
- parse-platform - LiveQuery Parse 服务器订阅不触发事件
- javascript - Vue中的Intro.js多页面导航,不起作用
- java - Battlenet API Android Studio 获取 Token?