爬取糗事百科并用微信自动发送消息

爬取糗事百科并用微信自动发送消息

"""


### 爬取糗事百科,微信自动发送

# https://www.qiushibaike.com/text/
# https://www.qiushibaike.com/text/page/1/



import requests
from bs4 import BeautifulSoup
ret = requests.get('https://www.qiushibaike.com/text/page/1/')
# print(ret.text)

ll = []
soup = BeautifulSoup(ret.text, 'lxml')

article_list = soup.find_all(name='div', id=True, class_='article')
for article in article_list:
    content = article.find(name='div', class_='content').span.text

    ll.append(content)
print(ll)


# 微信自动发送消息
# wxpy:实现了we微信的接口   

# 注意:有写些微信是不能够登录网页版微信的,所以就验证不了,前提得用你的收集微信去扫描网页微信

# 安装pip install wxpy
from wxpy import *

# 实例化得到一个对象,微信机器人对象
import random
bot = Bot(cache_path=True)

@bot.register() # 接收从指定好友发来的消息,发送者即recv_msg.sender为指定好友girl_friend
def recv_send_msg(recv_msg):
    print('收到的消息:', recv_msg.text)   # recv_msg.text取得文本
    return random.choice(ll)

embed()
"""
posted @ 2020-04-08 22:26  alen_zhan  阅读(171)  评论(0编辑  收藏  举报
返回顶部