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

最新文章

  1. Android开发之扫描二维码开发
  2. Network
  3. java.map使用
  4. 解决spring+shiro cacheManager 登录报错
  5. 【63测试20161111】【BFS】【DP】【字符串】
  6. 水晶报表设置FiledObject支持HTML格式的数据
  7. 如何在Hadoop的MapReduce程序中处理JSON文件
  8. SAP Connector 3.0 .Net 开发
  9. Penetration test
  10. Ice笔记-利用Ice::Application类简化Ice应用
  11. linux之cal命令
  12. 将网站固定到开始菜单,自定义图标、颜色和Windows推送通知
  13. 拆开Ceph看队列和线程
  14. QTP11完美破解小笔记
  15. Unity3d 2017
  16. 对datagridview进行增删改(B)
  17. PSP(4.6——4.12)以及周记录
  18. 自然语言处理词向量模型-word2vec
  19. jquery圆角插件
  20. easyui datagrid列拖拽

热门文章

  1. HighChart利用servlet导出中文PNG图片乱码问题解决
  2. 数据库聚焦与非聚焦索引 事务处理 redis innodb引擎(九)
  3. [问题记录]cocos2dx编译打包apk过程&amp;问题记录
  4. July 05th 2017 Week 27th Wednesday
  5. pypy入门:pypy的安装及使用介绍
  6. 完整详解GCD系列(三)dispatch_group
  7. UVa 1608 - Non-boring sequences
  8. 网络解析json
  9. tp3.2中前台模板中日期时间的转换
  10. Redis数据类型(上)