赞
踩
这是很久之前写的1个爬虫了,也是我写的第一个爬虫,因为恰好网课开始了,很多工作要在电脑上学习了,总在手机上查英语单词比较费时费事,于是便想着写一个爬虫直接在电脑上查词会方便很多,所以写了一个爬取有道翻译的爬虫。
代码如下:
import urllib.request import urllib.parse import json while 1: content = input("请输入要翻译的内容:") url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule' data={} data['i'] = content data['from'] = 'AUTO' data['to'] = 'AUTO' data['smartresult'] = 'dict' data['client'] = 'fanyideskweb' data['salt'] = '15812376682056' data['sign'] = 'a1246b257926af8432be022564ff79f5' data['ts'] = '1581237668205' data['bv'] = '656f750600466990f874a839d9f5ad23' data['doctype'] = 'json' data['version'] = '2.1' data['keyfrom'] = 'fanyi.web' data['action'] = 'FY_BY_CLICKBUTTION' data = urllib.parse.urlencode(data).encode('utf-8') response = urllib.request.urlopen(url,data) html = response.read().decode('utf-8') target = json.loads(html) print("翻译结果为:%s"%(target['translateResult'][0][0]['tgt']))
运行结果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。