baohanblog

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

# 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
    # content=article.find(name=\'div\',class_=\'content\').text
    # content=article.find(class_=\'content\').text
    # print(content)
    # 入库
    # 我们放到列表中
    ll.append(content)
# print(ll)

# 微信自动发消息
# wxpy:实现了web微信的接口
# pip3 install wxpy
from wxpy import *
# 实例化得到一个对象,微信机器人对象
import random
bot=Bot(cache_path=True)

# friend = bot.search(\'袁超\')[0]
# print(friend)

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

 

分类:

技术点:

相关文章:

  • 2021-12-10
  • 2021-04-09
  • 2021-05-31
  • 2021-04-11
  • 2021-12-10
  • 2021-07-06
猜你喜欢
  • 2021-12-12
  • 2021-08-04
  • 2021-10-02
  • 2021-12-18
  • 2021-10-21
  • 2022-12-23
相关资源
相似解决方案