Python automatically scans wechat's list of non friends
Huny 2021-06-04 10:57:24


Recently, I found some old friends ready to chat, and found that some of them have been deleted , As a diver for many years, I don't know how many people have been blacklisted , But there is still a list of friends who are not friends , In the face of a huge number of friends, it's hard to get rid of them . Although you can send messages to everyone , To identify if you're a friend , But after all, it bothers other people , After some inquiry, it is found that when you click transfer, you will be prompted that you are not a friend , This is just click transfer, not real transfer . As a tech diver , We must do things well in a low profile . It has been used before appium I've played automation , Then I'll be familiar with it this time .

Get ready

1.Appium Environment building
Environment construction will not be introduced here , Need to see my previous article or Baidu
2. Manual operation flow chart to automatic operation flow chart

The initial flow chart , Then according to the flow chart to realize the operation process and logic . After the completion of the preliminary implementation, debug , There are a lot of loose logic in the process , And some of the holes in the frame , Finally, it can be scanned at one time . But there are still individual pits that need to be handled manually . Record it for the time being , Let's see the situation later .
Encounter pause is basically chat window can't recognize , You can slide up by hand , Let the program recognize the next chat window . You need to log in to wechat first .


from appium import webdriver
from import By
from import WebDriverWait
from import expected_conditions as EC
import time
from selenium.common.exceptions import StaleElementReferenceException
# platformVersion = input(' System version number (platformVersion): ')
# deviceName = input(' Equipment name (deviceName):')
desired_caps = {
"platformName": "Android", # System
"platformVersion": '10.0', # System version number
# "platformVersion": platformVersion, # System version number
"deviceName": 'b68548ed', # Device name
# "deviceName": deviceName, # Device name
"appPackage": "", # Package name
"appActivity": ".ui.LauncherUI", # app When it starts, it's mainly Activity
'unicodeKeyboard': True, # Use your own input method
'noReset': True # Retain session Information , You can avoid logging back in
def is_element_exist(driver, by, value):
""" Determine whether an element exists """
driver.find_element(by=by, value=value)
except Exception as e:
return False
return True
def break_key(n):
""" Click the back button """
for i in range(n):
el1 = wait.until(EC.element_to_be_clickable((By.ACCESSIBILITY_ID," return ")))
def swipe_up():
""" Slide the screen up """
# Get the... Of the screen size
size = driver.get_window_size()
# Get screen width width
width = size['width']
# Get screen height height
height = size['height']
x1 = width*0.5
y1 = height*0.45
y2 = height*0.3
print(" You slide ")
if __name__ == '__main__':
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
# Set the wait
wait = WebDriverWait(driver, 300)
status = True
n = 2
count = 1
while status:
# Click Address Book
a1 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc=\" The current page , Chat with \"]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView")))
# You slide
if n < 13:
# Enter the first chat window , The official account is 1, User element positioning from 2 Start , One page is the most 12, Every slide of the screen starts from scratch to 12.
g73 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc=' The current page , Chat with ']/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/[%d]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.View"%(n))))
print(" Entered the first place %d A friend chat window "%(count))
count += 1
n -= 1
g73 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc=' The current page , Chat with ']/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/[%d]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.View"%(n))))
print(" Entered the first place %d A friend chat window "%(count))
count += 1
# Determine whether the chat window has elements to send messages
is_weichat = is_element_exist(driver, "id", "")
if is_weichat == True:
while True:
# # If you have a message, click
(By.ID, ""))).click()
print(" Click to send a message ")
# Click on + Number
is_jia = is_element_exist(driver, 'id', '')
# Judge whether there is a plus sign
if is_jia == True:
el4 = wait.until(EC.element_to_be_clickable((By.ID, "")))
print(' Click on + Number ')
# Judge whether it is transfer
is_zhuanzhang = wait.until(EC.element_to_be_clickable((By.XPATH,"//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView")))
if is_zhuanzhang.text == " Transfer accounts ":
# is_zhuanzhang = is_element_exist(driver, 'xpath', '//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView')
# if is_zhuanzhang == True:
# Click transfer
el5 = wait.until(EC.element_to_be_clickable((By.XPATH,"//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView[2]")))
print(' Click transfer ')
# Input amount 0.01
el6 = wait.until(EC.element_to_be_clickable((By.ID,"")))
print(' Input amount ')
# Click confirm transfer
el7 = wait.until(EC.element_to_be_clickable((By.ID,"")))
print(' Click confirm transfer ')
# Judge if anyone knows
is_not_friend = is_element_exist(driver,'id','')
if is_not_friend == True:
# Click to see
el8 = wait.until(EC.element_to_be_clickable((By.ID,"")))
print(' Click to see ')
# Get the user name and print
el9 = wait.until(EC.element_to_be_clickable((By.ID,"")))
print(' The wechat name that is not a friend is :',el9.text)
with open('weixin.txt','a+')as f:
f.write(' Not a friend's wechat name :' + el9.text + '\n')
print(' return ')
n += 1
# If you don't know, return to
n += 1
print(' return ')
# If there is no transfer, return to the home page
print(' return ')
n += 1
# No, + No. returns to the home page
print(' return ')
n += 1
except StaleElementReferenceException:
print(' Capture StaleElementReferenceException abnormal ')

It's scanned here 200 More than one friend , You may need to slide up manually

The list of non friends will be generated in the current directory txt Keep the file

A couple of anomalies happened by accident , I don't know why

In general, the functions have been basically realized , There are also details. Let's see the optimization later

Please bring the original link to reprint ,thank
Similar articles