当前位置:网站首页>Free your hands and automatically brush Tiktok
Free your hands and automatically brush Tiktok
2022-06-25 21:17:00 【Next Lu Kou】
cause
Because the project needs , Studying recently appium automation , Learning is boring , Want to do something that will arouse interest , It happens that I like to brush Tiktok at ordinary times , Think about whether you can free your hands to automatically brush Tiktok , If you have an idea, let's take action , To make 、 To make 、 To make
(ps: The code is simple , The environment is difficult to build )
One 、 Environment building :
1、 The environment I used :
①、Python3.7
②、Node.js14.9.0
③、JDK1.8
④、Andriod SDK
⑤、Appium1.9.1
⑥、Appium-Python-Client
The above is my environment , The installation process will not be explained one by one , Study appium The biggest difficulty is the installation of the environment ,80% Of them died in the environment , And then it didn't and then ,10% More than one hundred percent of people have been upset by the environment for more than a week , Only the rest 10% Good character , Can be installed smoothly . Friends must not give up on environmental construction , come on. , cheer up !
Attach the package download address :
link :https://pan.baidu.com/s/1n7C6-3r5f68oJbBkDuX_jQ
Extraction code :82wi
Two 、 start-up APP
1、 Connect the phone :
Set the developer mode on the phone ----> allow USB debugging ---->cmd Input in adb devices----> The following figure shows the successful connection :
2、 Get the package name and Activity name :
①、 Open what you need app
②、 stay cmd Input in :adb shell dumpsys window w |findstr / |findstr name= The following figure shows :
③、 Package name and Activity be known as :com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity
3、 start-up app Parameters :
desired_caps = {}
desired_caps['platformName'] = 'Android' # Test your phone's operating system |`iOS`, `Android`, or `FirefoxOS`|
desired_caps['platformVersion'] = '10' # Mobile operating system version | for example : `7.1`, `4.4`|
desired_caps['deviceName']='JTK5T19917008667' # Mobile device name
desired_caps['appPackage'] = 'com.ss.android.ugc.aweme' # You want to run Android The package name of the app
desired_caps['appActivity'] = 'com.ss.android.ugc.aweme.splash.SplashActivity
' # What you want to launch from your app package Android Activity name
desired_caps['automationname']='UiAutomator2' # Android 7 This parameter must be added when the above equipment is started , location toast When prompted, you must also add
desired_caps['noReset']='True' # To prevent repeated installation app
4、 start-up app:
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
5、 In order to facilitate later maintenance , Write it in configuration package :
①、 Get the configuration file code :
The name of the configuration file can be .cfg perhaps .ini Closing document , Pictured :
#coding:utf-8
import os
from configparser import ConfigParser
"""
obtain descaps.cfg Data in the configuration file
"""
class Dictionary(dict):
'''
hold descaps.cfg Add values to the parameters in dict
'''
def __getattr__(self, keyname):
# If key If the value does not exist, the default value is returned "not find config keyname"
return self.get(keyname, "descaps.cfg No corresponding keyname")
class Config(object):
'''
ConfigParser Secondary packaging , Get... In the dictionary value
'''
def __init__(self):
# Set up descaps.cfg route
current_dir = os.path.dirname(__file__)
top_one_dir = os.path.dirname(current_dir)
file_name = top_one_dir + "/data/descaps.cfg"
# Instantiation ConfigParser object
self.config = ConfigParser()
self.config.read(file_name)
# according to section hold key、value Write in dictionary
#print(self.config.sections())
for section in self.config.sections():
setattr(self, section, Dictionary())
#print(self.config.items(section))
for keyname, value in self.config.items(section):
setattr(getattr(self, section), keyname, value)
def getconf(self, section):
'''
usage :
conf = Config()
info = conf.getconf("main").url
'''
if section in self.config.sections():
pass
else:
print(" In file Can't find the section")
return getattr(self, section)
②、 start-up APP Encapsulates the code :
#coding=utf-8
from appium import webdriver
from tools.configoperate import Config
import os
class BasicSetting(object):
def __init__(self,conf_section):
"""
Initialization start appium Parameter configuration
:param conf_section: descaps.cfg For each configuration item in the file section value
:param platformname Which mobile operating system platform to use
:param devicename The type of mobile device or simulator used , Need to be in cmd Under orders , knock adb devices see
:param platformversion Mobile operating system version
:param apppackage What to test app The package name , Get orders :aapt dump badging apk route , see package
:param appactivity Required test app Entry page for , Get orders :aapt dump badging apk route , see launchable-activity
:param unicodekeyboard
:param noreset Before this session , Do not reset the application state
"""
conf = Config()
info = conf.getconf(conf_section)
self.automationname = info.automationname
self.platformname = info.platformname
self.devicename = os.popen('adb shell getprop ro.product.model').read()
self.platformversion = os.popen('adb shell getprop ro.build.version.release').read()
self.apppackage = info.apppackage
self.appactivity = info.appactivity
self.noreset = info.noreset
def start_parameter(self):
desired_caps={
'automationName':self.automationname,
'platformName':self.platformname,
'deviceName':self.devicename,
'platformVersion':self.platformversion,
'appPackage':self.apppackage,
'appActivity':self.appactivity,
'noReset':self.noreset
}
# Connect appium server, Send the startup parameters
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
try:
# Set the default input method of the phone to ADB keyboard
os.system('adb shell ime set com.android.adbkeyboard/.AdbIME')
except Exception as e:
print(e)
print(" The phone may not be installed ADB keyboard typewriting ")
return self.driver
Above we talked about starting app What parameters and conditions are required , There may be some differences between the version and the mobile phone , Cause failure to start app, You are welcome to leave a message to discuss specific issues
3、 ... and 、 Get into app, Auto slide page
1、 Slide page :
①、appium The official way for me is :
swipe(self, start_x, start_y, end_x, end_y, duration=None)
Slide from one point to another
start_x It starts to slide x coordinate , start_y It starts to slide y coordinate
end_x Is the end point x coordinate ,end_y Is the end point y coordinate
duration It's duration , Unit millisecond , Can not fill , Generally set as 500-1000 Between
We have encapsulated the use of lower sliding according to the use as follows :
class SwipePlace(object):
""" operation app Slide up 、 Decline in 、 Left slide 、 Right slip """
def __init__(self,driver):
self.driver = driver
def get_size(self):
""" Get the phone screen size """
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
return (x,y)
def swipe_up(self,dt=500):
""" You slide """
screen = self.get_size()
sx = screen[0] * 0.5
sy = screen[1] * 0.75
ex = screen[1] * 0.5
ey = screen[1] * 0.25
self.driver.swipe(sx, sy, ex, ey,dt)
def swipe_down(self,dt=50):
""" Slide down """
screen = self.get_size()
sx = screen[0] * 0.5
sy = screen[1] * 0.25
ex = screen[0] * 0.5
ey = screen[1] * 0.75
self.driver.swipe(sx, sy, ex, ey, dt)
def swipe_left(self,dt=50):
""" Scroll left """
screen = self.get_size()
sx = screen[0] * 0.75
sy = screen[1] * 0.5
ex = screen[0] * 0.25
ey = screen[1] * 0.5
self.driver.swipe(sx, sy, ex, ey, dt)
def swipe_right(self,dt=50):
""" Slide to the right """
screen = self.get_size()
sx = screen[0] * 0.25
sy = screen[1] * 0.5
ex = screen[0] * 0.75
ey = screen[1] * 0.5
self.driver.swipe(sx, sy, ex, ey, dt)
3、 Automatic slide douyin app page
It said so much , Just to prepare for the next cycle , The following code is simple , Is to cycle through the page , Call the code we wrote above , as follows :
#coding=utf-8
from time import sleep
from common.basicMessage import BasicSetting
from tools.swipeplace import SwipePlace
driver = BasicSetting("douyin").start_parameter()
swi = SwipePlace(driver)
for i in range(1,10000):
swi.swipe_up()
sleep(10)
driver.quit()
Let's do less cycling , Protecting glasses is the most important , Ha ha ha , Now we have finished the automatic video brushing , This time I just did a simple video , The waiting time of a video can be controlled by itself , I will continue to optimize when I am free , Let's take a look at the effect , The video was uploaded B standing , Maybe a little fuzzy .
Video address .
https://www.bilibili.com/video/BV1o5411P7SS/
边栏推荐
- Vbpr (visual Bayesian personalized ranking) paper summary
- Nmap is simple and practical
- Openocd compilation and installation
- IPtables
- Alicloud disk mounted locally
- OBD Position Overview
- IPv4 and IPv6 (powercert animated videos)
- JS__ This, arguments, cloning, ternary operator__ Duyi
- Patrol script
- Big end and small end
猜你喜欢

Install JDK, MySQL and nexus under Linux (tar package installation)

1.1-mq visual client preliminary practice

Volatile qualifier

Alicloud disk mounted locally

Decryption of APP parameters of a cross-border export e-commerce - dunhuang.com

What is a server? (Powercert animated videos)

Heavy update! Yolov4 latest paper! Interpreting yolov4 framework

Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection

The beginning of manjaro's journey

Mutual conversion of CString and char*
随机推荐
The SH runtime directly reported an error syntax error near unexpected token ` $'. \r‘
[nailing scenario capability package] exhibition admission
[data recovery in North Asia] a data recovery case in which the upper virtual machine data is lost due to the hard disk failure and disconnection of raid6 disk array
Send a more awesome website, which can convert curl commands into code in any language
[nailing scenario capability package] ranking of enterprise employees' points
Lesson 4 beautifulsoup
Tencent music knowledge map search practice
ThreadLocal class
JS__ Prototype, prototype chain, call/apply__ Duyi
Node connection MySQL
The beginning of manjaro's journey
Server pressure troubleshooting top
The difference between strcpy and memcpy
Get the root directory of the package at compile time from buildreoot
A simple file searcher
[important notice] developer document update (12.13-12.19)
Illustration tcp/ip - Chapter 3 and 4 notes
Ensure the decentralization and availability of Oracle network
[nailing - scenario capability package] nailer card
Svn various color states