zoukankan      html  css  js  c++  java
  • 基于Python自动发送QQ群消息

    1.准备工作

    此次测试基于python3,需要安装qqbot、bs4、requests库。

    qqbot项目地址:https://github.com/pandolia/qqbot.git

    pip qqbot 
    pip install bs4
    pip install requests

    #更改qqbot配置文件

    以下配置是为了通过邮件发送授权二维码完成授权操作。

    2.代码部分

    #coding:UTF-8
    import qqbot
    import requests
    import bs4
    import time
    
    ##SentQQ
    class QQ(object):
        def __init__(self):
            self.qqnumber = '1234567890'
            self.message = '信息自动推送功能test!!!'
            self.groupname = ['交流群']
            self.bot = qqbot._bot
    
        def sendMsgToGroup(self,msg,group,bot):
            for group in group:
                bg=bot.List('group', group)
                if bg is not None:
                    bot.SendTo(bg[0],msg)
    
        def main(self):
            self.bot.Login(['-q', self.qqnumber])
            self.sendMsgToGroup(self.message,self.groupname,self.bot)
    
    ##爬取数据
    class GetData(object):
        def __init__(self):
            self.rooturl = 'https://www.xxxx.com'
            self.url = self.rooturl + '/ah/20?lang=1'
            self.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'}
    
        def getdata(self):
            response = requests.get(self.url,headers=self.headers)
            if int(response.status_code) == 200:
                htmldata = bs4.BeautifulSoup(response.text,'html.parser')
                blognumber = 0
                result = "[%s] 技术文章推荐: 
     
    " %(time.strftime('%Y-%m-%d',time.localtime(time.time())))
                for k in htmldata.find_all('a'):
                    if blognumber <= 10:
                        try:
                            if k['title'] != '':
                                blogurl = self.rooturl + str(k['href'])
                                blogtitle = str(k['title'])
                                bloginfo = "%d.[%s] 
      %s 
    " %(blognumber,blogtitle,blogurl)
                                result = result + bloginfo
                                blognumber += 1
                        except:
                            pass
    
            return result
    
    
    if __name__ == '__main__':
        server = QQ()
        server.message = GetData().getdata()
        server.main()

    3.添加计划任务

    00 07 * * * python3 /root/bin/autoqq.py
    

     

    4.效果图

     

    关注公众号
    微信公众号
  • 相关阅读:
    SuiteCRM-7.7.6 (Ubuntu 16.04)
    Mautic-2.2.0 (Ubuntu 16.04)
    Limesurvey-2.55 (Ubuntu 16.04)
    视频会议20方100点 v2.66.1.18
    cuda和tensorflow对应关系
    pointnet++运行
    ubuntu使用anaconda安装tensorflow
    ubuntu安装搜狗输入法
    add the icon of the pycharm
    ubuntu中文界面改成英文界面
  • 原文地址:https://www.cnblogs.com/mascot1/p/9904673.html
Copyright © 2011-2022 走看看