In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to use Python+Appium to automatically rob WeChat red packet", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use Python+Appium to automatically rob WeChat red packet" can help you solve your doubts.
Environmental preparation
Appium environment
Android phone
Usb data line
Python environment
Realization idea
We receive red packets and messages are automatically set to the first, so we open the first to determine whether there is a red packet, if not, hide this window. If so, judge whether the red packet can be received, and if so, get the red packet, otherwise delete the red packet (otherwise it will affect the later judgment)
Then the cycle is run and judged.
Code
First of all, let's take a look at the configuration information, because I am using the real Xiaomi 9 Android 10 system. Please fill in the following specific information according to your actual situation:
Desired_caps = {"platformName": "Android", # system "platformVersion": "10.0", # system version number "deviceName": "b68548ed", # device name "appPackage": "com.tencent.mm", # package name "appActivity": ".ui.LauncherUI", # app startup master Activity'UI # use built-in input method 'noReset': True # to retain session information You can avoid re-login}
Because after clicking on the red packet, you need to judge whether the red packet after clicking is received, that is, whether there is an open word.
So we define a method to determine whether the element exists or not, and the code implementation is as follows:
Def is_element_exist (driver, by, value): try: driver.find_element (by=by, value=value) except Exception as e: return False else: return True
Since the record of the received red packet will be deleted after it is received by itself or by others, we define a method to delete the received red packet. The code is as follows:
Def del_red_envelope (wait, driver): # long press the received red packet R8 = wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ahs")) TouchAction (driver). Long_press (R8). Perform () time.sleep (1) # Click the delete wait.until shown after the long click (EC.element_to_be_clickable ((By.ID)) "com.tencent.mm:id/dt5")) .click () # Click the pop-up box to delete the option wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ffp")) .click ()
At the same time, it is possible that the first message is pushed by the official account, which makes it impossible to judge, so we judge that as long as there is no red packet in it, we will hide it and wait for a new red packet to happen.
# delete the first chat box def del_red_public (wait, driver): # long press the first chat box R8 = wait.until (EC.element_to_be_clickable ((By.ID) ("com.tencent.mm:id/fzg")) TouchAction (driver). Long_press (R8). Perform () time.sleep (1) # Click the delete wait.until shown after the long click (EC.element_to_be_clickable ((By.XPATH) "/ / android.widget.TextView [@ text=' does not show the chat']") .click () # Click the pop-up box to delete the option wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ffp")) .click ()
The complete code is as follows:
From appium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom appium.webdriver.common.touch_action import TouchActionfrom selenium.webdriver.support import expected_conditions as ECimport timedesired_caps = {"platformName": "Android", # system "platformVersion": "10.0", # system version number "deviceName": "b68548ed", # device name "appPackage": "com.tencent.mm" # package name "appActivity": ".ui.LauncherUI", # app startup master Activity 'unicodeKeyboard': True, # use built-in input method' noReset': True # to retain session information Can avoid re-login} # to determine whether the element exists def is_element_exist (driver, by, value): try: driver.find_element (by=by, value=value) except Exception as e: return False else: return True# deletes the red packet record def del_red_envelope (wait) Driver): # long press the received red packet R8 = wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ahs")) TouchAction (driver). Long_press (R8). Perform () time.sleep (1) # Click the delete wait.until shown after the long button (EC.element_to_be_clickable ((By.ID)) "com.tencent.mm:id/dt5")) .click () # Click the pop-up box delete option wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ffp")) .click () # Delete the first chat box def del_red_public (wait Driver): # long press the first chat box R8 = wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/fzg")) TouchAction (driver). Long_press (R8). Perform () time.sleep (1) # Click the delete wait.until shown after long press (EC.element_to_be_clickable ((By.XPATH)) "/ / android.widget.TextView [@ text=' does not show the chat']") .click () # Click the delete option wait.until (EC.element_to_be_clickable ((By.ID, "com.tencent.mm:id/ffp")) in the pop-up box. Click () if _ _ name__ = ='_ main__': driver = webdriver.Remote ("http://localhost:4723/wd/hub",") Desired_caps) # set to wait wait = WebDriverWait (driver, 500) while True: # enter the first chat window g73 = wait.until (EC.element_to_be_clickable ((By.ID) "com.tencent.mm:id/fzg")) g73.click () print ("entered the first chat window") # determine whether the chat window is the official account is_weichat = is_element_exist (driver, "id") "com.tencent.mm:id/u1") if is_weichat = = True: # while True: # if you have a red packet, click wait.until ((By.ID) ("com.tencent.mm:id/u1")). Click () print ("clicked on the red packet") # determine whether the red packet is received is_open = is_element_exist (driver, "id", "com.tencent.mm:id/f4f") print ("red packet is received:" Is_open) if is_open = = True: # Red packet was not received Click to open the red packet wait.until (EC.element_to_be_clickable (By.ID) ("com.tencent.mm:id/f4f")). Click () print ('already received the red packet') # return to the group chat driver.keyevent (4) # Delete the received red packet record del_red_envelope (wait, driver) print ('delete the received red packet Wait for the new red packet') driver.keyevent (4) else: # return to the group chat driver.keyevent (4) # Delete the received red packet record del_red_envelope (wait, driver) print ('delete the unavailable red packet Wait for new red packet') driver.keyevent (4) else: print ('hide this chat box if there is no red packet') # return to group chat driver.keyevent (4) # Delete the first official account window del_red_public (wait) Driver) print ('Hidden the first chat box') reads here This article "how to use Python+Appium to automatically rob WeChat red packet" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.