本来想爬微信公众号的,突然想起这个,自己以前就想做的事,结果网上一搜一大把,参照一篇博客,几分钟就能写出来

 

直接贴代码:

ps:search里是写你微信好友自己的昵称,不是备注!不是备注!不是备注!

# coding=utf-8
from threading import Timer
from wxpy import *
import requests


bot = Bot()


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 send_news():
    try:
        content,note = get_news()
        my_friend = bot.friends().search(u\'少爷\')[0]
        my_friend.send(content)
        my_friend.send(note)
        my_friend.send(u\'我在胡建等你~!\')
        t = Timer(60, send_news)
        t.start()
    except:
        my_friend = bot.friends().search(u\'舒然\')[0]
        my_friend.send(u\'啊哦,你最好看一下,今天发送失败了\')



if __name__ == \'__main__\':
    send_news()



是不是很简单???

参照博客:传送门

收藏 打印