Python爬虫实现简单的爬取有道翻译功能示例
作者:Kelisita 时间:2022-05-30 14:08:37
本文实例讲述了Python爬虫实现简单的爬取有道翻译功能。分享给大家供大家参考,具体如下:
# -*- coding:utf-8 -*-
#!python3
import urllib.request
import urllib.parse
import json
while True :
content = input("请输入需要翻译的内容:(按q退出)")
if content == 'q' :
break
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=https://www.baidu.com/link'
head = {}
head[ 'User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
data = {}
data['type'] = 'AUTO'
data['i'] = content
data['doctype'] = 'json'
data['xmlVersion'] = '1.8'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['action'] = 'FY_BY_CLICKBUTTON'
data['typoResult'] = 'true'
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url,data,head)
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
target = json.loads(html)
print("翻译结果:%s" %(target['translateResult'][0][0]['tgt']))
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/qq_33638791/article/details/52824236
标签:Python,爬虫
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Django中提供的6种缓存方式详解
2023-03-24 14:55:49
深入理解Python虚拟机中描述器的实现原理
2021-08-05 21:20:48
SQL语言基本语句介绍
2008-07-24 13:32:00
基于python实现百度翻译功能
2023-09-06 15:14:18
![](https://img.aspxhome.com/file/2023/3/70883_0s.jpg)
渗透和改变 非洲web 2.0网站Logo
2008-01-22 13:31:00
![](https://img.aspxhome.com/file/UploadPic/20081/22/2008122135247290s.jpg)
MySQL中XML数据的XPath支持
2009-12-15 21:57:00
mysql出现10061错误解决办法
2010-07-04 13:36:00
python中enumerate函数遍历元素用法分析
2021-08-07 10:07:18
Python时区设置方法与pytz查询时区教程
2022-05-20 17:11:51
python MultipartEncoder传输zip文件实例
2022-04-20 07:22:57
python树莓派红外反射传感器
2022-12-05 16:11:47
![](https://img.aspxhome.com/file/2023/9/89399_0s.jpg)
Python测试开源工具splinter安装与使用教程
2022-07-22 01:56:36
![](https://img.aspxhome.com/file/2023/3/65083_0s.png)
Oracle 用户权限管理方法
2009-08-15 10:54:00
Dreamweaver量身打造Wordpress留言板(三)
2009-12-13 18:45:00
![](https://img.aspxhome.com/file/UploadPic/200912/13/1444290-13s.gif)
ASP、PHP与javascript根据时段切换CSS皮肤的代码
2008-09-01 17:26:00
ASP实现长文章自动分页的函数代码
2008-10-10 17:09:00
Python面向对象程序设计之私有变量,私有方法原理与用法分析
2022-04-17 01:37:50
![](https://img.aspxhome.com/file/2023/3/69053_0s.png)
鼠标驱动图片变化
2009-07-26 10:03:00
asp如何验证IP地址?
2010-06-10 18:37:00
Golang中goroutine和channel使用介绍深入分析
2023-07-07 16:51:48