程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python WeChat automation tool development series 01_Automatically obtain WeChat chat information (available in July 2022)

編輯:Python

前言

一個需求
需要利用Python+第三方庫wxauto It is used to automatically obtain chat information on WeChat,Thereby, the information can be automatically processed for the second time according to its own needs,
such as auto-responders,Another example is to automatically send files or other.
這邊使用Python的第三方庫`wxauto`來進行開發,而不是`itchat`
--- 記錄於2022年07月

使用Python3的第三方庫wxauto, 它適用於Windows的微信客戶端

官網: https://github.com/cluic/wxauto

原因

這邊使用wxauto來進行開發,而不是itchat,原因如下

itchatAll previous tutorials,
In essence, the interface of WeChat's web page is used for data interaction.

如果你想要使用itchat的代碼的話,

  • 1、First test whether your account can still log in to the WeChat webpage

https://wx.qq.com/
Tencent official although no official statement,But you can search for relevant information
大概從去年開始(The time is not quite certain),Most WeChat accounts cannot continue to log in to the WeChat webpage,Only a few accounts can still log in.
原因未知.

  • 2、If you can log in to the WeChat web version Then you can close this blog and find it onlineitchatcode to learn to run,

如果登錄失敗,Then maybe you can try itwxautoThat is the method mentioned here to run.


環境

Windows 10
Python 3.8.10
Windows 10WeChat client version:3.7.5.23 (英文版本)

注:Both Chinese and English versions of the WeChat client are available
沒什麼太大區別.

安裝

安裝Python3的第三方庫wxauto,具體步驟如下

官網: https://github.com/cluic/wxauto

在cmdWindow execute the following command to install

  • 安裝第三方庫wxauto
python3 --version
python3 -m pip install wxauto -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 查看wxauto是否安裝成功
python3 -c "import wxauto; print(wxauto.VERSION)"

使用步驟

1. 新建main.py

The first article here only introduces getting the chat information of the default window

from wxauto import *
# 獲取當前微信客戶端
wx = WeChat()
# 獲取會話列表
wx.GetSessionList()
###############################
# 1、Get default window chat information
###############################
def get_default_window_messages():
# The default is the currently selected window of the WeChat window
# 輸出當前聊天窗口聊天消息
msgs = wx.GetAllMessage
for msg in msgs:
print('%s : %s' % (msg[0], msg[1]))
# 獲取更多聊天記錄
wx.LoadMoreMessage()
msgs = wx.GetAllMessage
for msg in msgs:
print('%s : %s' % (msg[0], msg[1]))
if __name__ == '__main__':
get_default_window_messages()

2. 打開微信

  • windows10Open the WeChat client
  • Scan the code to log in normally
  • Open the WeChat window to the front,Do not minimize or shrink to the bottom menu

3. 執行代碼

打開cmd窗口,在cmd窗口執行:

If no third party library is installed,參考上面的安裝Steps to install and then execute the following command

cd 你的main.py所在路徑
python3 main.py

4. 輸出

cmdThe window normally outputs the chat information of your default WeChat window

後續

Just started writing a series of articles here,I want to develop my own blog and WeChat public account

如果對你有幫助,You can follow it if it's convenient The WeChat official account on the left side of the blog(Click on my avatar to enter the personal center,on the lower left)

如有問題的話,You can also leave a message directly through the official account,There is a WeChat reminder here,Respond promptly within a few hours

也可直接在CSDNBlog message or private message message,There is no WeChat reminder for this,So here may reply within a day or a few days

The location of the WeChat public account:打開個人中心也就是這個鏈接
https://blog.csdn.net/xiaozi_001?type=blog
左側下方

如有需求,

Want to automate some WeChat operations to improve efficiency:

比如

  • Automatically send different chat messages to several WeChat groups

  • Automatically send different pictures to several WeChat groups

  • Automatically send different files to several WeChat groups


  • If you know the code yourself

If you know the code yourself, Look directly at third-party librarieswxauto的使用,Just write it yourself,

The blog will continue to be updated based on this series in the follow-up.

Welcome to comment and ask questions,方便的話 點贊收藏 關注下微信公眾號

  • If you don't know the code

Just want a simple WeChat processing tool to meet your needs

You can leave a message on WeChat public account or private message,

Post your specific needs,Here, the next secondary development will be carried out according to your needs


費用大概100RMB~500RMB不等,Determined according to your requirements complexity and development time

簡單的功能,比如上面提到的,一般100RMB就可以了

復雜的需求,It will be determined according to your requirements complexity and development time


Generally this meets the needs,After the development is completed and confirmed to the user, the payment will be made

The location of the WeChat public account:打開個人中心也就是這個鏈接
https://blog.csdn.net/xiaozi_001?type=blog
左側下方

如有需求,You can follow the WeChat public account to leave a message or leave a private message directly

The former can respond promptly within a few hours

The latter may not be seen in time,Reply in about a day or a few days


注:Just started thinking about making some orders in my spare time,Think about your future career plans

Orders that can be part-time developed for part-time requirements,微信自動化,QQ自動化,Static official website development, etc. can be

A series of tutorials will follow Welcome to communicate if necessary

其他

如有問題 歡迎提出

如有疑問 歡迎留言

如有作用 歡迎點贊

如有失效 歡迎留言

2022年07月 可用


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved