美文网首页爬虫项目汇总
给微信好友发消息

给微信好友发消息

作者: 一秆子数码 | 来源:发表于2019-04-28 14:22 被阅读0次

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"今天消息发送失败了")

相关文章

  • 给微信好友发消息

    api接口:https://www.liutianyou.com/api/?type=js&charset=utf...

  • Python 骚操作,自动拷贝U盘

    阅读文本大概需要 6 分钟。 Python 这门语言有非常多有趣的内容,比如给微信好友自动发消息、查看微信好友撤回...

  • 如何给微信好友,每天的8点自动发消息

    如何给微信好友,每天的8点自动发消息比如:早上好

  • python操作微信机器人自动回复

    运行下面的代码,可以自动给指定的微信好友发消息 运行下面的代码,好友发消息给你后自动回复 自动回复的内容用的是图灵...

  • 微信个人开发:定时给微信好友发消息

    最近需要每天给好友发送提醒消息,偶尔会忘记,所以研究了一下微信开发,发现微信官方有出台个人号API,供外部调用,十...

  • 叠猫猫让我玩坏了通讯录

    淘宝618出了一个叠猫猫活动,呐,就是这个活动,促使我给不少微信好友发消息, 帮我叠个猫猫~ 微信好友已经有好多个...

  • 免费清理僵尸粉引流套路解析

    微信里把你单删或者拉黑的好友,你发消息给对方,系统会提示你还不是对方好友,或消息已被拒收,此类好友俗称为微信僵尸粉...

  • 2017-11-05

    微信发消息给别人发多条

  • 给微信好友

    您好,我是孙传治,最近我加入了中国平安,在中国平安,我意识到了很多平时忽略掉的问题,学习到了很多知识,希望最好能和...

  • python给微信发消息

    老方法 用server酱,但是以前server酱一天可以发1000条信息,但是现在出了个Turbo版就只能一天发5...

网友评论

    本文标题:给微信好友发消息

    本文链接:https://www.haomeiwen.com/subject/wrvdnqtx.html