Python使用itcaht庫實現微信自動收發消息功能
itchat庫
模擬微信網頁登錄 通過python code接受/發送微信消息 實現微信聊天機器人:調用聊天機器人api,將接收到的微信消息傳給api,再將api返回的消息傳給微信展示如何使用itchat發送微信消息
# !pip install itchatimport itchat
在當前文件夾下生成二維碼圖片,微信掃碼即可登錄網頁版微信
itchat.auto_login()
Getting uuid of QR code.Downloading QR code.Please scan the QR code to log in.Please press confirm on your phone.Loading the contact, this may take a little while.Login successfully as 小白
通過微信名稱查找接收消息的對象
users = itchat.search_friends(name='小白') # 這里是給自己發送消息user_name = users[0]['UserName']
對象表示成這樣的一個字符串
user_name
’@40f90812b2233588e8ebda1e8d8f01d48d32a384e31f0a96yaa4859a41123456’
toUserName指定接受消息的對象;每隔10s發送一次'hello world',發送3次
import timefor i in range(3): itchat.send('hello, world', toUserName=user_name) time.sleep(10)
總結
到此這篇關于Python使用itcaht庫實現微信自動收發消息的文章就介紹到這了,更多相關python itcaht庫微信自動收發消息內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. python如何換行輸出2. Python使用urlretrieve實現直接遠程下載圖片的示例代碼3. Python:UserWarning:此模式具有匹配組。要實際獲得組,請使用str.extract4. 解決Android Studio 格式化 Format代碼快捷鍵問題5. Java使用Tesseract-Ocr識別數字6. python如何計算圓的面積7. 詳解java google Thumbnails 圖片處理8. Vue實現聊天界面9. Android Studio中一套代碼多渠道打包的實現方法10. Android打包篇:Android Studio將代碼打包成jar包教程
