python调用金山词霸的api

准备

  1. python环境
  2. requests库

实现

调用每日一句的api

原理:通过requests的发送get请求,然后解析返回的数据。
每日一句api
具体的描述如上图。

import requests
import json

header = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36'
}
response = requests.get(url='http://open.iciba.com/dsapi/',params={'date':'2021-02-07'},headers=header)  # date参数为空代表今天,此处设置的为2021年2月7日
response_next = requests.get(url='http://open.iciba.com/dsapi/',params={'date':'2021-02-07','type':'next'},headers=header)  # type参数为next表示今天的下一天
response_last = requests.get(url='http://open.iciba.com/dsapi/',params={'date':'2021-02-07','type':'last'},headers=header)  # type参数为last表示今天的上一天
print(response.json())  # 以json的格式接收返回的数据,因为file的默认格式为json
print(response_next.json())
print(response_last.json())

输出
得到的数据就可以用键值对(字典),的方式提取出来了

{'sid': '4031', 'tts': 'https://staticedu-wps.cache.iciba.com/audio/b0986b1b60494fa17cfc38971aabc14a.mp3', 'content': 'Since you are like no other being ever created since the beginning of time, you are incomparable.', 'note': '因为你和有史以来任何人类都不相同,所以你是无可比拟的。', 'love': '0', 'translation': '新版每日一句', 'picture': 'https://staticedu-wps.cache.iciba.com/image/ce2c96a2bb268204fae0ccd42b75ea9d.jpg', 'picture2': 'https://staticedu-wps.cache.iciba.com/image/de53bff1897be4e4cc0926d55c403efb.jpg', 'caption': '词霸每日一句', 'dateline': '2021-02-07', 's_pv': '0', 'sp_pv': '0', 'fenxiang_img': 'https://staticedu-wps.cache.iciba.com/image/741d428bbc89492602350003fd59f267.png', 'picture3': 'https://staticedu-wps.cache.iciba.com/image/bdb590d2e1692d6b2ffd7f4877ae2012.jpg', 'picture4': 'https://staticedu-wps.cache.iciba.com/image/4f967ac3c6488b1302fb148378daf7ff.jpg', 'tags': []}
{'sid': '4032', 'tts': 'https://staticedu-wps.cache.iciba.com/audio/fe7f398766ee10e40bbe65c1b44cf757.mp3', 'content': 'When the lord closes a door, somewhere he opens a window.', 'note': '当主关上了一扇门,就会在别处打开一扇窗。', 'love': '0', 'translation': '新版每日一句', 'picture': 'https://staticedu-wps.cache.iciba.com/image/d4a4ed3e674ab24a0d9401251d476fdc.jpg', 'picture2': 'https://staticedu-wps.cache.iciba.com/image/505e425b2fe494b2e615f1f7b6e93a47.jpg', 'caption': '词霸每日一句', 'dateline': '2021-02-08', 's_pv': '0', 'sp_pv': '0', 'fenxiang_img': 'https://staticedu-wps.cache.iciba.com/image/b410c581226a81006dc5c6eee8a948a8.png', 'picture3': 'https://staticedu-wps.cache.iciba.com/image/521a447f864b7e0ca73733f3534ed410.jpg', 'picture4': 'https://staticedu-wps.cache.iciba.com/image/ed0132ec6c1dcaa9aea43f1f35d3c51c.jpg', 'tags': []}
{'sid': '4030', 'tts': 'https://staticedu-wps.cache.iciba.com/audio/42957b7398712b3123565d429dc2178f.mp3', 'content': 'All friendship changes, but for the good ones it will only make it stronger. \xa0', 'note': '所有的友情都会变,但有的改变会让其变得强大。', 'love': '0', 'translation': '新版每日一句', 'picture': 'https://staticedu-wps.cache.iciba.com/image/9e0f8c614ba6449b031088070b095a41.jpg', 'picture2': 'https://staticedu-wps.cache.iciba.com/image/8be5dcb9b38e0c8a00f209490eb61085.jpg', 'caption': '词霸每日一句', 'dateline': '2021-02-06', 's_pv': '0', 'sp_pv': '0', 'fenxiang_img': 'https://staticedu-wps.cache.iciba.com/image/b31309d244c9dff23e4f7e0658ac7eaa.png', 'picture3': 'https://staticedu-wps.cache.iciba.com/image/3aa3a05a23c1d6fb130da6f9742be0ad.jpg', 'picture4': 'https://staticedu-wps.cache.iciba.com/image/f4dc51137bbe7a42ff6483780ab0df14.jpg', 'tags': []}

调用金山词霸的查词api

因为key申请不了了so over
查词api可以使用百度翻译的api申请地址

python百度api调用

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值