使用wxpy怎么自動發送微信消息?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
思路整理:1、進入心靈雞湯網頁,使用python獲取心靈雞湯內容
2、登陸微信,找到需要發送的朋友
3、發送獲取的內容
實現如下:

2、登陸微信,搜索朋友,進行發送
import requests
import wxpy
from bs4 import BeautifulSoup
# 微信網頁登陸
bot = wxpy.Bot(console_qr=2,cache_path='botoo.pkl')
# 獲取心靈雞湯中的最新內容,可以參考其他爬蟲隨便查看怎么爬蟲
def get_msg():
url = 'http://www.59xihuan.cn/index_1.html'
h = requests.get(url)
html = h.text
news_bf = BeautifulSoup(html,"html.parser")
msg = news_bf.find('div', class_='pic_text1')
news = msg.text
# print(msg)
# print(news)
return news
# 給朋友發送消息
def send_msg():
try:
# 添加朋友微信昵稱
friend = bot.friends().search(u'xxxxx')[0]
friend.send(get_msg())
29 except:pass
if __name__ == '__main__':
send_msg()其他發送類型格式:
發送文本消息:friend.send('文本消息')
發送圖片消息:friend.send_image('圖片消息.jpg')
發送視頻消息:friend.send_video('視頻消息.mov')
發送文件消息:friend.send_file('文件消息.zip')
以動態的方式發送圖片:friend.send('@img@圖片消息.jpg')
看完上述內容,你們掌握使用wxpy怎么自動發送微信消息的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。