Python 爬取必应翻译
封装爬取必应翻译功能
import requestsdef transation(text):tunsXml = requests.get('https://cn.bing.com/translator/')if tunsXml.status_code != 200:raise Exception('')pos = tunsXml.text.find('IG:"')IG = tunsXml.text[pos + 4:pos + 4 + 32]cookie = tunsXml.cookiesCounts = 1url = 'https://cn.bing.com/ttranslatev3?isVertical=1&&IG={}&IID=translator.5028.{}'.format(IG, Counts)postdata = '&fromLang=en&text={}&to=zh-Hans'.format( requests.utils.quote(text))headers = {'accept': '*/*','accept-encoding': 'gzip, deflate, br','accept-language': 'zh-CN,zh;q=0.9,en;q=0.8','content-type': 'application/x-www-form-urlencoded','sec-fetch-mode': 'cors','sec-fetch-site': 'same-origin','origin': 'https://cn.bing.com','referer': 'https://cn.bing.com/translator/','content-length': str(len(postdata))}res = requests.post(url=url, headers=headers, data=postdata, cookies=cookie)if res.status_code != 200:raise Exception('')return res.json()[0]['translations'][0]['text']
另一通用版本其他各国语言翻译成中文
import requests
def start_tran(content):from_data = {}for i in content:if '\u4e00'<= i <= '\u9fff':return contentelse:from_data = {'fromLang':'auto-detect','text': content, 'to': 'zh-Hans'}return translate(from_data)def translate(from_data):tunsXml = requests.get('https://cn.bing.com/translator/')if tunsXml.status_code != 200:raise Exception('')pos = tunsXml.text.find('IG:"')IG = tunsXml.text[pos + 4:pos + 4 + 32]url = 'https://cn.bing.com/ttranslatev3?isVertical=1&&IG={}&IID=translator.5028.78'.format(IG)headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'}r = requests.post(url,data = from_data ,headers=headers)r.raise_for_status()r.encoding = r.apparent_encodingdata = r.json() # 取出翻译结果detectedLanguage = data[0]translations = detectedLanguage['translations']result = translations[0]['text']return resultprint(start_tran("hello,world"))
Python 爬取必应翻译相关推荐
- python爬百度翻译-Python爬取百度翻译(利用json提取数据)
本篇文章给大家带来的内容是关于Python爬取百度翻译(利用json提取数据),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 工具:Python 3.6.5.PyCharm开发工具. ...
- python 翻译库本地库_利用python爬取并翻译GEO数据库
原标题:利用python爬取并翻译GEO数据库 GEO数据库是NCBI创建并维护的基因表达数据库,始于2000年,收录了世界各国研究机构提交的高通量基因表达数据,现芯片集数据量高达12万以上.想要从这 ...
- Python爬取百度翻译及有道翻译
Python爬取百度翻译及网易有道翻译 百度翻译 一.简介 明确翻译链接,百度翻译链接:https://fanyi.baidu.com/,但是该链接不能为我们提供翻译的内容,此时需要在chrome浏览 ...
- 求解Python 爬取百度翻译手机版{errno:997,from:zh,to:en,query:\u4eba\u751f\u82e6\u77ed}怎么办
环境:python3.7.3 import requestsurl = "https://fanyi.baidu.com/basetrans" data = {"quer ...
- python如何爬取sci论文_利用python爬取并翻译GEO数据库
GEO数据库是NCBI创建并维护的基因表达数据库,始于2000年,收录了世界各国研究机构提交的高通量基因表达数据,现芯片集数据量高达12万以上.想要从这里面挖掘(bai piao)数据,发个sci提前 ...
- python爬取百度翻译返回:{'error': 997, 'from': 'zh', 'to': 'en', 'query 问题
解决办法: 修改url为手机版的地址:http://fanyi.baidu.com/basetrans User-Agent也用手机版的 测试代码: # -*- coding: utf-8 -*- & ...
- Python 爬取必应(壁纸+搜索词)
爬取必应壁纸 经常使用必应应该可以发现,其主页每天都会更新一张图片,这些图片很好看,希望每天能够下载收藏每张图片.具体请看这个网站:必应每日高清壁纸(https://bing.ioliu.cn/) 效 ...
- python爬百度翻译-爬虫 python爬取百度翻译接口 超详细附源码
前言 今天教大家如何利用 firefox 分析百度翻译的接口,并用python爬取接口.大家学会后可以干一些有趣的事情,比如做一个自己的翻译软件. 具体内容 1 - 找到URL接口 进入百度翻译的网址 ...
- 利用python爬取百度翻译内容
利用python可以实现对百度翻译内容的爬取,具体过程如下: 前期工作 本程序的测试环境为python3.5,Chrome浏览器.进入百度翻译的页面,点开F12进入开发者调试工具,点击network, ...
- python爬取谷歌翻译
由于谷歌翻译的api官方接口是有次数限制和收费的,于是乎,自己动手丰衣足食,通过抓包,js加密拼接,自己用python封装了一个爬取谷歌中英文翻译的接口,目前比较稳定无次数限制,地址:http://g ...
最新文章
- ARM 之五 发展史及各时期内核(ARM1 ~ ARM11 / Cortex)介绍
- matlab 对三维图像旋转,求助,二维图像如何绕轴旋转成为三维图像
- feign 序列化_Spring Cloud Feign 配置 FastJson
- 如何解决使用mac聚焦搜索无法搜索软件的情况
- coco训练集darknet_YOLOv4: Darknet 如何于 Docker 编译,及训练 COCO 子集
- DOM判断节点类型分分钟搞定
- VS2010 + VS2008 快捷键
- 分布式数据库中间件–(1) Cobar初始化过程
- jsp购物车系统01
- win10或11非华为电脑安装最新的电脑管家(支持移动应用引擎)安装方法及问题解决
- VNC远程控制服务器卡顿
- angular7.0+ngx-weui公众号开发,开发及框架搭建(一)
- 数据路:三人行,必有我师!
- TVS二极管和稳压二极管区别和原理
- “做自己擅长又有兴趣的事情,是最幸福最快乐的” – 记我的大学老师
- 关于Gstreamer出现“Could not send sticky events”的机制探究
- 华为HCNA路由技术篇—OSPF协议细节详解
- win10安装红警运行出现FATALString Manager failed to initilaized properly
- 【STM32L552ZET6QU】小白入门资料汇总
- java导出excel表格设置行高_EasyExcel之不使用对象灵活生成Excel,并且调整行高、自动列宽与自由合并...
热门文章
- c语言程序设计谭浩强题库,谭浩强c语言程序设计习题答案
- SpringBoot+Maven整合MyBatis时打包漏掉mapper的xml文件【解决resources调用静态资源失败404】
- 使用 charles 进行抓包
- vue 引入json地图_前端学习 之 Vue 引入Echarts地图
- mysql是应用软件还是系统软件_数据库管理系统属于应用软件吗?
- 欢迎大家关注我的博客,让我们一起在知识的海洋中并肩自由翱翔!
- Crystal Ball—甲骨文水晶球风险管理软件(概念以及实战——中级案例篇)
- 微信开发者工具安装使用SVN
- Python语言程序设计课程论文——Python小游戏
- C语言项目源码2022必看必学版