我换了个网络好了!!
然后加入了延时,顺利翻译了import urllib.request
import urllib.parse
import json
import openpyxl
import time
#打开excel文件
wb = openpyxl.load_workbook('MD - Summary list of harmonised standards.xlsx')
ws = wb.active
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
head={}
head['User-Agent']='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'
data={}
data['i']= ''
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']='16079142839884'
data['sign']='7fa30595c70a9a765816fda28b64b9ac'
data['lts']='1607914283988'
data['bv']='4b9de992aa3d23c2999121d735e53f9c'
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_REALTlME'
#定义翻译函数
for each_row in ws.iter_rows(min_row=2,max_row=10):
data['i'] = each_row[3].value
print(data['i'])
data2 = urllib.parse.urlencode(data).encode('utf-8')
req=urllib.request.Request(url,data2, head)
response=urllib.request.urlopen(req)
html = response.read().decode('utf-8')
target = json.loads(html, strict=False)
each_row[3].value = target['translateResult'][0][0]["tgt"]
print(each_row[3].value)
time.sleep(8)
wb.save('翻译.xlsx')
上面是程序
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
=========== RESTART: D:\03-其他\个人\Training Course\翻译协调标准\Translate.py ===========
Safety of machinery - General principles for design - Risk assessment and risk reduction (ISO 12100:2010)
机械安全-设计一般原则的风险评估和风险降低(ISO 12100:2010)
Safety of machinery - Basic concepts, general principles for design - Part 1: Basic terminology, methodology (ISO 12100-1:2003)
机械安全——基本概念、一般原理设计-第1部分:基本术语、方法(ISO 12100 -声学)
Safety of machinery - Basic concepts, general principles for design - Part 2: Technical principles (ISO 12100-2:2003)
机械安全-基本概念,设计一般原则-第2部分:技术原理(ISO 12100 - 2:2003)
Safety of machinery - Risk assessment - Part 1: Principles (ISO 14121-1:2007)
机械安全-风险评估-第1部分:原则(ISO 14121 - 1:2007)
Safety of machinery - Minimum gaps to avoid crushing of parts of the human body
机械安全——最小间隙避免破碎的人体的部分
Safety of machinery - Human body measurements - Part 1: Principles for determining the dimensions required for openings for whole body access into machinery
机械安全-人体测量-第1部分:原则确定所需的尺寸为全身进入机械开口
Safety of machinery - Human body measurements - Part 2: Principles for determining the dimensions required for access openings
机械安全-人体测量-第2部分:原则确定访问开口所需的尺寸
Safety of machinery - Human body measurements - Part 3: Anthropometric data
机械安全-人体测量-第3部分:人体测量数据
Safety of machinery - Two-hand control devices - Functional aspects - Principles for design
机械安全-双手控制装置功能方面为设计原则
>>>
这是执行结果。
可能是我前面访问太频繁,有道标记了我的IP吗? |