在线咨询
QQ咨询
服务热线
服务热线:13125520620
TOP

利用wxpy进行微信信息发送详解(一)

发布时间:2018-5-31 浏览:3098

利用wxpy进行微信信息自动发送,简直是骚扰神器,除非拉黑你。
 
那我们就来设置一个场景吧,五秒发送一次,一次发送10条
 
首先我们来整理一下思路:
 
  ♦1.首先我们要从网上爬去我们想要发送的内容
 
  ♦2.登录微信找到想要发送的微信好友
 
  ♦3.讲爬取的信息发送给好友
 
首先我们需要的模块:  
 
  ♦import requests
 
  ♦import wxpy,threading,time
 
  ♦from bs4 import BeautifulSoup
 
代码草稿及调试如下:
 
复制代码
import wxpy,threading,requests,time#如果报错:AttributeError: module 'wxpy' has no attribute 'Bot'
# 一定要检查是不是文件夹名字或者文件名字和你要用模块是不是一致了不能一样
from bs4 import BeautifulSoup
def get_next(nub):
    '''获取要发送的内容'''
    url = 'http://www.59xihuan.cn/index_'#我们观察到每一页只是和上一页的url中一个数据不一样而且是有规律性的递增
    response = requests.get(url= url + str(nub) + '.html')
    a = BeautifulSoup(response.text,'html.parser')#进行解析
    txte1 = a.find_all('div',class_='pic_text1')#找到需要的内容的那个标签所在的行
    #print(txte1)
    new_txte = []
    for temp in txte1:
        new_txtes = temp.text#从经验上讲从一般的经验上讲:  :string 被用于短文本输入(用户名,电子邮件,密码,标题等)。
                                                                 #:text 被用于预计文本长度较长的文本输入(描述,评论内容等)。
        news_text = new_txtes.replace('\r\n        \r\n    ', '')
        news_text = news_text.replace('\r\n       \n', '')#去掉前后空格
        new_txte.append(news_text)#从经验上讲从一般的经验上讲:  :string 被用于短文本输入(用户名,电子邮件,密码,标题等)。
                                                                 #:text 被用于预计文本长度较长的文本输入(描述,评论内容等)。
 
    # print(new_txte)
    return new_txte
 
def Dingshi(num):
    '''找到好友并发送信息'''
    num =num
    try:
        bot = wxpy.Bot(cache_path=True)#打开微信,读取cooker信息cache_path=True。
        my_friend = bot.friends().search(u'xxxxx')[0]#从好友中找到要发送的具体的那个人
        a = get_next(num)#在登录后调用获取获取发送信息函数
        for c in range(len(a)):#把列表里面的额内容依次发送出去
            my_friend.send(a[c])#发送信息
    except:pass
    # timer1=threading.Timer(1,Dingshi,(text))#可以使用定时器进行无线发送
    # timer1.start()
 
if __name__ == '__main__':
    for i in range(10):
        time.sleep(10)
        Dingshi(i)#传这个参主要是给他里面调用get_next函数传值
复制代码
整理代码:
 
复制代码
import wxpy,threading,requests,time
from bs4 import BeautifulSoup
def get_next(nub):
    '''获取要发送的内容'''
    url = 'http://www.59xihuan.cn/index_'
    response = requests.get(url= url + str(nub) + '.html')
    a = BeautifulSoup(response.text,'html.parser')
    txte1 = a.find_all('div',class_='pic_text1')
    new_txte = []
    for temp in txte1:
        new_txtes = temp.text
        news_text = new_txtes.replace('\r\n        \r\n    ', '')
        news_text = news_text.replace('\r\n       \n', '')#去掉前后空格
        new_txte.append(news_text)#获取文本内容,注意几个获取文本的区别
    return new_txte
 
def Dingshi(num):
    '''找到好友并发送信息'''
    num =num
    try:
        bot = wxpy.Bot(cache_path=True)#打开微信,读取cooker信息cache_path=True。
        my_friend = bot.friends().search(u'xxxx')[0]#从好友中找到要发送的具体的那个人
        a = get_next(num)#在登录后调用获取获取发送信息函数
        for c in range(len(a)):#把列表里面的额内容依次发送出去
            my_friend.send(a[c])#发送信息
    except:pass
 
if __name__ == '__main__':
    for i in range(10):
        time.sleep(10)
        Dingshi(i)
复制代码
♦十秒发一次一次依次发十条,你可以随便sing一发送次数只要for i in range(10):把这个10改一下就行了,至于一次发十条是因为一页就有十条,如果像一次发更多的话的可以让一次多读取几页存起来,但是如果一次发太多,会被微信监听,然后拒接,
 
 
 
 

TAG
软件定制,软件开发,瀚森HANSEN
0
该内容对我有帮助