完美修复google翻译失效的问题

简介: 使用chrome的小伙伴应该都知道有个页面一键翻译,对于英语相当蹩脚的我来说灰常好用,然而…

背景

使用chrome的小伙伴应该都知道有个页面一键翻译,对于英语相当蹩脚的我来说灰常好用,然而…

2010年,谷歌拒绝同意审查其在中国的搜索结果后,撤出了在中国的搜索引擎业务。

2017年,谷歌为中国用户推出了改进版的Google翻译应用。

2022 google translate 退出中国市场

google翻译最终还是退出了中国。

解决方法

手动干预配置DNS,将google translate解析到提供服务的地区来达到效果。

使用以下脚本可以获取延迟较低的ip

windows下有一个很好用的快速修改hosts文件的工具SwitchHosts。

ip 源

translate地址

源代码

对代码做了部分注释,各位看官慢用. 高手请忽略

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project :dataTransfer
@File :Google Translate.py
@Author :ninesun
@Date :2022/11/18 8:43
@Desc:
'''
import os
from concurrent.futures import ThreadPoolExecutor
# from pyperclip import copy
os.system('title 查找最佳的谷歌翻译IP')
ipAndSpeed = []
ips = '''
142.250.4.90
172.253.114.90
172.217.203.90
172.253.112.90
142.250.9.90
172.253.116.90
142.250.97.90
142.250.30.90
142.250.111.90
172.217.215.90
142.250.11.90
142.251.9.90
108.177.122.90
142.250.96.90
142.250.100.90
142.250.110.90
172.217.214.90
172.217.222.90
142.250.31.90
142.250.126.90
142.250.10.90
172.217.195.90
172.253.115.90
142.251.5.90
142.250.136.90
142.250.12.90
142.250.101.90
172.217.192.90
142.250.0.90
142.250.107.90
172.217.204.90
142.250.28.90
142.250.125.90
172.253.124.90
142.250.8.90
142.250.128.90
142.250.112.90
142.250.27.90
142.250.105.90
172.253.126.90
172.253.123.90
172.253.62.90
142.250.98.90
172.253.113.90
'''
def ipList():
    '''获取IP地址'''
    return { i.strip() for i in ips.splitlines() if i.strip() }
def pingInfo(ip):
    '''ping Ip 获取ms 最终取最小值'''
    cmd = f'ping /n 1 {ip}'
    for echoTxt in os.popen(cmd):
        if '请求超时。' in echoTxt:
            ipAndSpeed.append([ip, 999])
            print(ip, '超时')
            return
        if echoTxt := echoTxt.strip(): # 去掉头尾的空格
            echoTxt = echoTxt.replace(' ', '') # 去掉字符串中间的空格,结合ping的结果来理解
            if ',平均=' in echoTxt:
                ms = int(echoTxt.split('=')[-1].replace('ms', ''))  # 分割平均=xxms
                ipAndSpeed.append([ip, ms])
                print(ip, f'{ms}ms')
                return
def fastScan():
    with ThreadPoolExecutor(20) as Pool:  #使用线程池,设置20个线程,可修改
        Pool.map(pingInfo, ipList())
fastScan()
sortedSpeed = sorted(ipAndSpeed, key=lambda x: x[-1]) # 按照延迟大小升序排序
for n, i in enumerate(sortedSpeed, 1): # 将一个sortedSpeed数据对象组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。 此例当中下标从1开始
    i[-1] = '超时' if i[-1] == 999 else f'{i[-1]}ms'
    print(f'【{str(n).zfill(2)}】\t{i[0]}\t {i[1]}') # zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0。
fastip, ms = sortedSpeed[0]
print(f'\n最佳IP是:【{fastip}】,响应时间:【{ms}】')
# copy(hostTxt)
# print(f'\n\n设置hosts的内容“已复制到剪贴板”:   {hostTxt}\n\n\n按【任意键】打开hosts目录,然后【手动】修改。',
#       end='')
#
# os.system('pause>nul')
# os.popen('explorer /select,C:\Windows\System32\drivers\etc\hosts')

技术点

这个代码逻辑比较简单,你先ping一个ip看看结果再来理解这个代码。

python多线程

ThreadPoolExecutor

海象运算

这里我的py环境是3.8.6 ,这个语法idea报错,但是代码可以运行。怀疑是Pycharm(2017.2.3)的bug.

  if echoTxt := echoTxt.strip(): # 头尾空格去掉
            echoTxt = echoTxt.replace(' ', '') # 正在 Ping 142.250.4.90 具有 32 字节的数据  把这句话的空格替换掉
            if ',平均=' in echoTxt:
                ms = int(echoTxt.split('=')[-1].replace('ms', ''))  # 分割平均=xxms
                ipAndSpeed.append([ip, ms])
                print(ip, f'{ms}ms')
                return

完美解决

1、延迟较低的ip

【01】  142.250.4.90   86ms
【02】  142.250.101.90   184ms
【03】  142.250.107.90   207ms
【04】  142.250.30.90  210ms
【05】  142.250.126.90   212ms
【06】  142.250.100.90   213ms
【07】  142.250.8.90   213ms
【08】  172.217.195.90   216ms
【09】  142.250.28.90  218ms
【10】  172.217.214.90   222ms
【11】  142.250.10.90  223ms
【12】  142.250.136.90   223ms
【13】  142.250.125.90   224ms
【14】  142.250.128.90   226ms
【15】  172.217.215.90   228ms
【16】  142.250.96.90  229ms
【17】  172.253.124.90   230ms
【18】  172.253.113.90   230ms
【19】  172.253.62.90  231ms
【20】  142.250.12.90  231ms
【21】  172.253.123.90   233ms
【22】  142.250.9.90   234ms
【23】  172.253.126.90   234ms
【24】  108.177.122.90   234ms
【25】  172.253.115.90   237ms
【26】  172.253.112.90   237ms
【27】  142.250.11.90  238ms
【28】  172.253.114.90   239ms
【29】  172.217.222.90   240ms
【30】  142.250.31.90  242ms
【31】  142.250.105.90   243ms
【32】  142.250.98.90  243ms
【33】  172.217.203.90   246ms
【34】  142.250.112.90   246ms
【35】  142.250.97.90  253ms
【36】  142.250.111.90   253ms
【37】  172.217.204.90   253ms
【38】  172.217.192.90   296ms
【39】  142.250.0.90   299ms
【40】  142.251.5.90   307ms
【41】  142.250.110.90   307ms
【42】  142.250.27.90  311ms
【43】  142.251.9.90   311ms
【44】  172.253.116.90   323ms
最佳IP是:【142.250.4.90】,响应时间:【86ms】

2a5997c69b8d4e7a90263327363b99bf.png

2、配置hosts文件,

如果有Switchhosts比较方便,没有的话打开 C:\Windows\System32\drivers\etc\hosts 修改同样可行.

3、翻译结果

142.250.4.90 这个ip最快延迟86ms.

参考

1、字符串语法

2、海象语法

目录
相关文章
|
1月前
|
Web App开发
在 HTML 中禁用 Chrome 浏览器的 Google 翻译功能
在 html 标签中添加 translate=“no” 属性,浏览器将不会翻译整个页面。
36 0
|
8月前
|
自然语言处理 JavaScript
vue3-ts-vite:Google 多语言调试 / 网页中插入谷歌翻译元素 / 翻译
vue3-ts-vite:Google 多语言调试 / 网页中插入谷歌翻译元素 / 翻译
99 0
|
5月前
|
JavaScript 测试技术
【sgGoogleTranslate】自定义组件:基于Vue.js用谷歌Google Translate翻译插件实现网站多国语言开发
【sgGoogleTranslate】自定义组件:基于Vue.js用谷歌Google Translate翻译插件实现网站多国语言开发
|
12月前
|
机器学习/深度学习 数据采集 自然语言处理
谷歌为1000+「长尾」语言创建机器翻译系统,Google翻译已支持部分小众语言
谷歌为1000+「长尾」语言创建机器翻译系统,Google翻译已支持部分小众语言
|
Web App开发 存储 缓存
如何在Google Chrome浏览器中修复“ Err_SSL_Protocol_Error”?
如何在Google Chrome浏览器中修复“ Err_SSL_Protocol_Error”?
1180 0
|
Web App开发 API 网络安全
Google 翻译插件不能用了怎么办
Google 翻译退出中国
4654 4
Google 翻译插件不能用了怎么办
|
网络协议 JavaScript Java
Google Java编程风格规范(2020年4月原版翻译)
Google Java Style Guide 这份文档是Google Java编程风格规范的完整定义。当且仅当一个Java源文件符合此文档中的规则, 我们才认为它符合Google的Java编程风格。 与其它的编程风格指南一样,这里所讨论的不仅仅是编码格式美不美观的问题, 同时也讨论一些约定及编码标准。然而,这份文档主要侧重于我们所普遍遵循的规则,
810 0
|
机器学习/深度学习 人工智能 自然语言处理
谷歌神经网络翻译系统发布后,我们和Google Brain的工程师聊了聊
9 月 27 日,谷歌在 arXiv.org 上发表论文《Google`s Neural Machine Translation System: Bridging the Gap between Human and Machine Translation》介绍谷歌的神经网络翻译系统(GNMT)后,「机器之心」第一时间进行了详细的解读和报道,重磅 | 谷歌翻译整合神经网络:机器翻译实现颠覆性突破(附论文)。
245 0
|
机器学习/深度学习 自然语言处理 NoSQL
Paper:2017年的Google机器翻译团队《Transformer:Attention Is All You Need》翻译并解读(四)
Paper:2017年的Google机器翻译团队《Transformer:Attention Is All You Need》翻译并解读
|
自然语言处理 异构计算
Paper:2017年的Google机器翻译团队《Transformer:Attention Is All You Need》翻译并解读(三)
Paper:2017年的Google机器翻译团队《Transformer:Attention Is All You Need》翻译并解读