首页 技术 正文
技术 2022年11月17日
0 收藏 698 点赞 4,752 浏览 2374 个字

利用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_txtedef 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_txtedef 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:passif __name__ == '__main__':
for i in range(10):
time.sleep(10)
Dingshi(i)

♦十秒发一次一次依次发十条,你可以随便sing一发送次数只要for i in range(10):把这个10改一下就行了,至于一次发十条是因为一页就有十条,如果像一次发更多的话的可以让一次多读取几页存起来,但是如果一次发太多,会被微信监听,然后拒接,

♦文章的读取可在python爬取小说详解(一)中有详讲,wxpy会在随后进行详解一下。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290