Psoriasis of wechat group , It refers to the users who send small advertisements in the wechat group with no lower limit , They are the most hated group of wechat people . If you are familiar with early risers, you can know that I have a technical exchange group , But since its establishment, it has been plagued by small advertisements . They disguise themselves as normal people, mingle with the crowd, and then constantly send out advertising bombing , Seriously disrupted the atmosphere of technology exchange within the group .
Or to harass every member of the group without saying a word .
Although it's not clear what drives them to be the strongest wechat group with psoriasis ( Maybe it's banknote capacity ), But after too many harassment , I began to wonder if I could use Python Kill them .
In fact, the idea at the beginning is very simple , There are two steps , First of all, you can identify these people, and then Python Kick them out .
But these two steps , Every step is not easy , Let's talk about the first step How to accurately identify These users , There is no data on the Internet and there is no good identification standard , I can only do feature recognition with my brain . After these months , Sample training of nearly 100 advertising users , This is me. “ Artificial intelligence ” You can basically judge an abnormal user Meet at least three of the following :
No settings WeChat ID
Head portrait For the net girl
Wechat name For special symbols or expressions
Never Circle of friends
No, Circle of friends Background map
After passing, there will be no reply other than group application
And based on historical data , accord with 1、3 The user of the bar has a great probability of being a small advertising enthusiast , So the next thing to do is use Python Write code to find these people in wechat . After summing up this rule, I am optimistic that it is not difficult to realize this demand , Because I took it years ago Python Research on wechat friends , Whether it's wxpy still itchat It should not be complicated to operate , But it turns out I'm still too young
I don't know when to start , Although these libraries can be installed and used, wechat has basically Most people's access to wechat on the web has been banned , So when I use multiple wechat signals to scan the QR code for logging in to wechat , Without exception, it reminds me
<error><ret>1203</ret><message>
For your account security , This wechat is no longer allowed to log in to wechat .
You can use Windows Wechat or Mac Wechat logs in on the computer .
</message></error>
This is a headache , You can't go one by one manually check My thousands of wechat friends , So I started thinking about whether there were other solutions .
If you often write Python Reptiles , Then you will know that in some cases , Instead of using Requests Some disgusting anti climbing measures , Not as good as Selenium Easy to operate . So I want to use wechat based API After the failure of the idea of , I turned my eyes to the relatively stupid method ————pynput
pynput It's a utility model Python To control and monitor the computer mouse 、 Third party Library of keyboards , At this point, you probably understand what I want to do , Direct use API We can't get the data , So I'm like Selenium equally , Click on the simulation A friend to achieve the operation I want .
Let's talk about this library briefly , Because there are not many dependent libraries, it's easy to install , direct pip install pynput that will do , It's easy to use , For mouse operations, only coordinates are dependent , Look at demo
As the above GIF The demonstration is the same , First import pynput And an example of a mouse controller , Then submit the position of wechat in the status bar to mouse.position, So the mouse will move to that location , Reuse mouse.press To simulate the mouse click can automatically open wechat . So here comes the question , How to get the coordinates of the position I want ? You can't try it bit by bit !
pynput Except to make it possible to use Controller To control the mouse , You can also monitor the mouse , For example, use the following code to record the location of each click of the mouse after the program starts
from pynput import mouse
def on_move(x, y ):
print(' Move the mouse to {0}'.format(
(x,y)))
def on_click(x, y , button, pressed):
print('{0} In coordinates {1}'.format(' Mouse click ' if pressed else ' Mouse release ', (x, y)))
if not pressed:
return False
while True:
with mouse.Listener(on_move = on_move,on_click = on_click) as listener:
listener.join
So the next task is simple , We just need to keep the wechat window still , Record the coordinates of each key location ( Wechat icon location , Group chat window location , Location of individual group member's head image ) after , For example, we want to judge the first rule above, that is, to obtain whether the micro signal of each group member is set , You can simulate the following operations to achieve :
Click wechat app
Click the group chat you want
Click on the avatar of each group member in turn
Move to the location of the micro signal
double-click The micro signal
Copy the micro signal to determine whether it is the initial micro signal
In the process above , It's worth mentioning the last step , Copy we can use pynput Keyboard controller in , After double-click to select the corresponding micro signal, through the following code to achieve analog keyboard input Command + C Complete the copy operation
from pynput.keyboard import Key
from pynput.keyboard import Controller as Controller1
keyboard = Controller1
with keyboard.pressed(Key.cmd):
keyboard.press('c')
keyboard.release('c')
But pasting doesn't need to use pynput By simulating command+c To paste into another editing complex process , We can use third-party libraries pyperclip, Directly through the following two lines of code can be copied into character string
import pyperclip
pyperclip.paste
In the group members of the micro signal into character string after , Whether we judge the length of the string, regular expression or other methods, we can easily determine whether the member's micro signal is the initial one , Implementation rules 1 The judgment of the , The following code and dynamic diagram is to get the first group member micro signal The whole process
from pynput.mouse import Button, Controller
import time
from pynput.keyboard import Key
from pynput.keyboard import Controller as Controller1
import pyperclip
mouse = Controller
# Click wechat
mouse.position = (1046.14453125, 4.546875)
time.sleep(2)
mouse.press(Button.left)
mouse.release(Button.left)
# Click on the picture
mouse.position = (1194.140625, 441.05859375)
time.sleep(1)
mouse.press(Button.left)
mouse.release(Button.left)
# Click on the selected text
mouse.position = (965.60546875, 284.0390625)
time.sleep(1)
mouse.click(Button.left, 2)
keyboard = Controller1
with keyboard.pressed(Key.cmd):
keyboard.press('c')
keyboard.release('c')
time.sleep(1)
wechatid = pyperclip.paste
print(f" WeChat ID {wechatid} Suspected ad number " if len(wechatid) > 20 else f" WeChat ID {wechatid} It's not an ad number ")
We can see that the success has excluded wechat from the advertising number
The next step is to record the coordinate distance between each group member , And then loop to Simulation scrolling perhaps The drop-down To achieve the above process , You can use the micro signals of all members of the group according to the rules 1 Judge , Find the members of the exception Judge alone .
You can see that in the end 6 Wechat with suspected advertising number , Then, through the manual judgment of other rules, the two users are finally determined as high-risk users of advertising and removed .
By the above operation , Although it successfully kicked out two suspected advertising numbers , But on the whole it's still lost . It's still hard to judge whether or not to kick people , If you kick it wrong , Then fans -1, You can also find that you want to use Python It's still very difficult to find the psoriasis in the group , Use pynput You can do it at most Wechat name 、 Micro signal and head image ( Use picture recognition API) The judgment of the , But the more information hidden in the circle of friends is difficult to extract and mine .
meanwhile pynput With and selenium The same disadvantages , That's because The speed caused by simulating human operation is slow , And the way it's positioned Only coordinates are supported , Therefore, it is also necessary to ensure that the wechat window cannot be moved during the operation , Otherwise, all previously recorded elements will be invalid , It is suggested that developers can upgrade more positioning methods .
Learn from good examples Python Whether it's employment or sideline, it's good to make money , But learn to Python Still have a learning plan . Finally, let's share a complete set of Python Learning materials , For those who want to learn Python Let's have a little help !
Python All directions are Python Sort out the common technical points , Form a summary of knowledge points in various fields , The use of it is , You can find the corresponding learning resources according to the above knowledge points , Make sure you learn more comprehensively .
If a worker wants to do a good job, he must sharpen his tools first . Study Python Common development software is here , It saves you a lot of time .
When we were watching videos to learn , You can't just move your eyes and brain without hands , A more scientific way to learn is to use them after understanding , At this time, the hand training program is very suitable .
Optical theory is useless , Learn to knock together , Do it , Can you apply what you have learned to practice , At this time, we can make some practical cases to learn .
We learn Python Must be to find a well paid job , The following interview questions are from Ali 、 tencent 、 The latest interview materials of big Internet companies such as byte , And the leader Ali gave an authoritative answer , After brushing this set of interview materials, I believe everyone can find a satisfactory job .
Guarantee 100% free
】