随机返回经典语句接口API
2024-08-25 00:04:09
api接口:https://www.liutianyou.com/api/?type=js&charset=utf-8
可以单独将上面链接,在浏览器中查看效果
这是get请求,参数:type=js&charset=utf-8 返回一个js方法 方法名为writeText
如果你想在前端使用,在你想要显示的地方,写上下面两句代码就ok了:
<script type="text/javascript" src="https://www.liutianyou.com/api/?type=js&charset=utf-8"></script> <p id="hitokoto" style="text-indent: 25px;"><script>writeText()</script></p>
如果你想在后端使用,可用requests直接访问:
import requests,re
con =requests.get('https://www.liutianyou.com/api/?type=js&charset=utf-8')
print(con.content.decode('utf-8'))
res = re.findall("document.write\('(.*?)'\);",con.content.decode('utf-8'))
print(res[0])
顺便给出一个案例:
设置单位个时间内给好友发消息,如骚扰,如打闹:
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import random
import re bot = Bot() # linux执行登陆请调用下面的这句
# bot = Bot(console_qr=2,cache_path="botoo.pkl")
def get_news():
"""获取金山词霸每日一句,英文和翻译"""
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
content = r.json()['content']
note = r.json()['note']
return content, note def get_words():
con = requests.get('https://www.liutianyou.com/api/?type=js&charset=utf-8')
# print(con.content.decode('utf-8'))
#字节无法匹配,需要解码成字符串
res = re.findall("document.write\('(.*?)'\);", con.content.decode('utf-8'))
return res[0] def send_news():
try:
# contents = get_news()
contents = get_words()
print('contents is',contents)
# # 你朋友的微信名称,不是备注,也不是微信帐号。
my_friend = bot.friends().search('筱凝')[0]
my_friend.send(contents)
# # 每86400秒(1天),这里没10秒发送1次
t = Timer(10, send_news)
# 为了防止时间太固定,于是决定对其加上随机数
# ran_int = random.randint(0, 100)
# t = Timer(86400 + ran_int, send_news) t.start()
except: # 你的微信名称,不是微信帐号。
my_friend = bot.friends().search('mxh')[0]
my_friend.send(u"今天消息发送失败了")
参考:
https://blog.csdn.net/qq_37193537/article/details/89499956
https://www.liutianyou.com/260.html
最新文章
- Android开发之扫描二维码开发
- Network
- java.map使用
- 解决spring+shiro cacheManager 登录报错
- 【63测试20161111】【BFS】【DP】【字符串】
- 水晶报表设置FiledObject支持HTML格式的数据
- 如何在Hadoop的MapReduce程序中处理JSON文件
- SAP Connector 3.0 .Net 开发
- Penetration test
- Ice笔记-利用Ice::Application类简化Ice应用
- linux之cal命令
- 将网站固定到开始菜单,自定义图标、颜色和Windows推送通知
- 拆开Ceph看队列和线程
- QTP11完美破解小笔记
- Unity3d 2017
- 对datagridview进行增删改(B)
- PSP(4.6——4.12)以及周记录
- 自然语言处理词向量模型-word2vec
- jquery圆角插件
- easyui datagrid列拖拽