In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use Python to make Wechat customer service. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Overall idea: the use of automated test library to achieve the desired results.
Operating environment: PyCharm Python
Codeword flow
Get the PID of Wechat
Connect to Wechat
Some basic functions of Wechat
Get the message sent by the user to get the chat information the user finds a user in the chat interface to search for a user to send a text message to a user to delete a user
Some additional features of Wechat
Modify remarks add designated application friends one click add all application friends send pictures to the designated user to receive super user instructions, process related tasks to receive ordinary user instructions, reply to relevant content one click to delete all friends offline notification superuser disconnect automatically reconnect with other interfaces, complete related tasks collect information to automatically judge the amount and notify the superuser to dock to the database Determine whether the user notifies the friend with one click within the period of using the function, specifies the friend message, does not disturb the group, kicks out the member to forward the message, sends the content in the favorite message to the user, sends the local file to the user.
Get the PID of Wechat
The psutil library is used here, which roughly means to get all the processes and traverse the process ID that picks out Wechat
#! / usr/bin/env python #-*-coding:utf-8-*-# Author:smart_num_1 # Blog: https://blog.csdn.net/smart_num_1 from psutil import process_iter def get_pid (): PID = process_iter () name =''pid_num = 0 for pid_temp in PID: pid_dic = pid_temp.as_dict (attrs = [' pid' 'name']) if pid_dic [' name'] = 'WeChat.exe': name = pid_dic [' name'] pid_num = pid_dic ['pid'] break if name = =' WeChat.exe': return pid_num else: return False
Connect to Wechat
# create an instance object. There are two kinds of backend in Pywinauto: win32 and uia. The default is win32. You can use the spy++ and Inspect tools to determine which backend is suitable for writing. Here, Wechat uses' uia' self.app = Application (backend = 'uia') # to connect app to the Wechat that has successfully logged in. Here, you can connect with process ID, handle, and program path. Here, use PID self.app.connect (process = PID) # to navigate to the Wechat window self.win = app [u' Wechat']
Some basic functions of Wechat
Get the message sent by the user
Def get_text (self): data =''try: data = self.win.Edit2.get_value () with open ('. / temporary_text','w',encoding = 'utf-8') as f: f.write (data) except: pass return data # line:4
Get chat information user
Def get_users (self): user_lis = [] try: # navigate to the information list Get the object conunacation = self.win.child_window (title = "session", control_type = "List") # navigate to this location position = conunacation.rectangle () mouse.click (button = 'left',coords = (position.left + 100, position.top + 10)) # navigate to the position of the list, take its child controls, as to why, the list is a total container And every user exists in this container, and the child control users = conunacation.children () for user in users: user_lis.append (user.window_text ()) except: pass return user_lis
Find a user in the chat interface
Def find_user (self, user =''): # find the button with the specified name user = self.win.child_window (title = user, control_type = 'Text') # navigate to the button and get its relative position position = user .rectangle () # simulated click Coords is the click location mouse.click (button = 'left',coords = (position.left, position.top)) sleep (0.3)
Search for a user
Def search_ueser (self, user_name =''): # the method of finding a control is described in the previous function Search = self.win.child_window (title = "search", control_type = "Edit") position = search.rectangle () mouse.click (button = 'left', coords = (position.left + 100, position.top + 10)) sleep (0.1) mouse.click (button =' left', coords = (position.left + 100, position.top + 10)) # is not introduced here Enter the user's first name self.win.type_keys (user_name) sleep (0.6) self.win.type_keys ('{ENTER}')
Send a text message to a user
Def send_message (self, texts =''): # line:64 for text in texts. Split ('\ n'): # line:65 # another library is used here, because the input modules, emoticons, spaces, etc. included with pywinauto are automatically skipped or cannot be recognized. If text.isalnum (): copy (text.strip ()) hotkey ('ctrl',' v') else: self.win.type_keys (text) sleep (0.1) hotkey ('ctrl',' enter') # line:67 hotkey ('enter') # line:68
Delete a user
Def delete_user (self, user =''): user = self.win.child_window (title = user, control_type = 'Text') position = user.rectangle () mouse.click (button =' right', coords = (position.left-40, position.top)) # right here the menu pops up Click the delete chat option self.app.Menu ['delete chat'] directly from the menu. Click_input ('left') Thank you for reading! This is the end of the article on "how to use Python to make Wechat customer service". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.