In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail about the use of Python to achieve Wechat "take a pat", but it is possible, the content of the article is of high quality, so the editor shares it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Recently, Wechat "clap" has gone viral in various WeChat groups, and quickly occupied the list of hot topics.
So I had a whim, decided to use pyhton to automatically achieve Wechat "clap", did not expect to be really successful, the whole process only used 30 lines of code, the following to introduce you the specific implementation steps:
Highlights:
Use appium to simulate and control the phone and take screenshots, then locate the friends' avatar coordinates through image recognition, and finally use appium to simulate and double-click the avatar coordinates, so as to achieve the function of "take a pat".
Specific steps:
1. Use appium to control mobile phone
I have written a lot about the installation and use of appium before, so I will not repeat it here and go directly to the operation steps.
1. Open Wechat with python, with the following code:
Desired_caps = {"platformName": "Android", "deviceName": "VOG-AL00", "appPackage": "com.tencent.mm", "appActivity": ".ui Launcher UI", "noReset": "true", "fullReset": "false"} server = 'http://localhost:4723/wd/hub' driver = webdriver.Remote (server, desired_caps)
The difficulty lies in the configuration of desired_cap parameters. Here is another introduction:
PlatformName: represents the device operating system
DeviceName: represents the device name
Apppackage: represents the app package name
AppActivity: indicates the Activity name of the app entry.
Connect your phone to your computer, open developer mode, run this program, and you will find that your phone automatically opens Wechat.
Second, simulate double-click avatar
1. Introduction of principle
As we all know, Wechat "take a pat" is achieved by double-clicking a friend's profile picture, as shown in the following figure:
If you want to double-click the avatar, first get the coordinates of the avatar on the screen
Here is a function for you:
Target location module based on Python-opencv2: Aircv uses its find_template function to find the coordinate range of the target image in the original image, as follows:
Def matchImg (imgsrc, imgobj,confidencevalue = 0.7): imsrc = ac.imread (imgsrc) imgobj = ac.imread (imgobj) match_result = ac.find_template (imsrc, imgobj,confidencevalue) return match_result
The path of the original image of imgsrc= and the path of the target image to be found by imgobj=.
If not found, match_result=None
If found, the following data is returned:
{'result': (570.0, 2771.0),' rectangle': ((30, 1601), (30, 3941), (1110, 1601), (1110 confidence': 3941)), 'confidence': 0.999999463558197}
Where:
Result matches the central coordinate point of the picture on the original picture, that is, the click point we are looking for.
Rectangle is to match the quadrilateral coordinates of the picture on the original image.
Confidence is the matching similarity rate.
two。 So how to automatically get the coordinates of a friend's profile picture in the program?
In the client-side appium, we can make sure that the pixel of the avatar on the screen is 140x140. we can first save the friend's avatar, and then use ps to change the avatar to this pixel.
Then create a while loop in the program, and enter the friend chat box manually on the basis of the completion of the first step (in fact, you can also enter it automatically by identifying the profile picture of your friend).
Take a screenshot of the phone through appium and name it src.png, and import it and the avatar path (obj.png) into the detection function in 1:
Driver.save_screenshot ('src.png') imgsrc='src.png' imgobj='obj.png' match_result=matchImg (imgsrc, imgobj)
If None is returned, the chat window does not detect the profile picture of a friend. Continue the cycle.
If the avatar coordinates are detected, the returned coordinate data is parsed, and the double-click coordinate position is simulated by for loop:
If match_result is not None: result = [match_result ['rectangle'] [0], match_result [' rectangle'] [3]] for i in range (2): driver.tap (result,100) print ('success') else: print ('avatar not found')
In this way, it's done.
Isn't it easy?
This paper introduces the main idea of simulating Wechat "take a pat" with python. If you are interested, you can go on and achieve some interesting functions, such as monitoring Wechat group chat, "patting" whoever sends a message, or taking pictures of group chat users one by one, which is very interesting.
On the use of Python to achieve Wechat "take a pat", unexpectedly can share here, I hope the above content can be of some help to 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.