1.点击进入官网下载页面 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.注意下载位置,点击同意协议,下载相应的版本
3.双击安装包,然后下一步,!!!注意安装位置,默认是C:\Program Files\Java,尽量不要修改。修改请记住路径
4.添加环境变量
- CLASSPATH
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
注意上边最开始有个点
- JAVA_HOME
C:\Program Files\Java\jdk1.8.0_191
- Path
%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
在cmd终端中输入java和javac不报异常,说明安装成功
- ANDROID_HOME
C:\...\Android\android-sdk
- Path
%ANDROID_HOME%\tools
%ANDROID_HOME%\platform-tools
设置----连点5次关于----出现开发者模式,点击进入
进入开发者模式----勾选usb调试
1. 在夜神模拟器安装路径下的bin目录下执行cmd进入终端
2. 输入 adb devices后,出现提示
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
3. 再输入 nox_adb.exe connect 127.0.0.1:62001后,出现提示
connected to 127.0.0.1:62001
4. 最后再次输入adb devices后,出现提示
List of devices attached
127.0.0.1:62001 device
1. adb devices
C:\Program Files (x86)\Nox\bin>adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
2. nox_adb.exe connect 127.0.0.1:62001
C:\Program Files (x86)\Nox\bin>nox_adb.exe connect 127.0.0.1:62001
already connected to 127.0.0.1:62001
3. adb devices
C:\Program Files (x86)\Nox\bin>adb devices
List of devices attached
127.0.0.1:62001 device
from appium import webdriver
# 初始化配置,设置Desired Capabilities参数
desired_caps = {
'platformName': 'Android',
'deviceName': 'SM-G955F',
'appPackage': 'com.ss.android.ugc.aweme',
'appActivity': '.main.MainActivity'
}
# 指定Appium Server
server = 'http://localhost:4723/wd/hub'
# 新建一个driver
driver = webdriver.Remote(server, desired_caps)
# 获取模拟器/手机的分辨率(px)
width = driver.get_window_size()['width']
height = driver.get_window_size()['height']
print(width, height)
# 获取视频的各种信息:使用appium desktop定位元素
print(driver.find_element_by_id('bc').text) # 发布者名字
print(driver.find_element_by_id('al9').text) # 点赞数
print(driver.find_element_by_id('al_').text) # 留言数
print(driver.find_element_by_id('a23').text) # 视频名字,可能不存在,报错
定位元素及获取其文本内容的方法
start_x = width // 2 # 滑动的起始点的x坐标,屏幕宽度中心点
start_y = height // 3 * 2 # 滑动的起始点的y坐标,屏幕高度从上开始到下三分之二处
distance = height // 2 # y轴滑动距离:屏幕高度一半的距离
end_x = start_x # 滑动的终点的x坐标
end_y = start_y-distance # 滑动的终点的y坐标
# 滑动
driver.swipe(start_x, start_y, end_x, end_y)
import time
from appium import webdriver
class DouyinAction():
"""自动滑动,并获取抖音短视频发布者的id"""
def __init__(self, nums:int=None):
# 初始化配置,设置Desired Capabilities参数
self.desired_caps = {
'platformName': 'Android',
'deviceName': 'SM-G955F',
'appPackage': 'com.ss.android.ugc.aweme',
'appActivity': '.main.MainActivity'
}
# 指定Appium Server
self.server = 'http://localhost:4723/wd/hub'
# 新建一个driver
self.driver = webdriver.Remote(self.server, self.desired_caps)
# 获取模拟器/手机的分辨率(px)
width = self.driver.get_window_size()['width']
height = self.driver.get_window_size()['height']
print(width, height)
# 设置滑动初始坐标和滑动距离
self.start_x = width//2 # 屏幕宽度中心点
self.start_y = height//3*2 # 屏幕高度从上开始到下三分之二处
self.distance = height//2 # 滑动距离:屏幕高度一半的距离
# 设置滑动次数
self.nums = nums
def comments(self):
# app开启之后点击一次屏幕,确保页面的展示
time.sleep(2)
self.driver.tap([(500, 1200)], 500)
def scroll(self):
# 无限滑动
i = 0
while True:
# 模拟滑动
print('滑动ing...')
self.driver.swipe(self.start_x, self.start_y,
self.start_x, self.start_y-self.distance)
time.sleep(1)
self.get_infos() # 获取视频发布者的名字
# 设置延时等待
time.sleep(4)
# 判断是否退出
if self.nums is not None and self.nums == i:
break
i += 1
def get_infos(self):
# 获取视频的各种信息:使用appium desktop定位元素
print(self.driver.find_element_by_id('bc').text) # 发布者名字
print(self.driver.find_element_by_id('al9').text) # 点赞数
print(self.driver.find_element_by_id('al_').text) # 留言数
print(self.driver.find_element_by_id('a23').text) # 视频名字,可能不存在,报错
# # 点击【分享】坐标位置 671,1058
# self.driver.tap([(671, 1058)])
# time.sleep(2)
# # 向左滑动露出 【复制链接】 580,1100 --> 200, 1100
# self.driver.swipe(580,1100, 20, 200, 1100)
# # self.driver.get_screenshot_as_file('./a.png') # 截图
# # 点击【复制链接】 距离右边60 距离底边170 720-60,1280-170
# self.driver.tap([(660, 1110)])
# # self.driver.get_screenshot_as_file('./b.png') # 截图
def main(self):
self.comments() # 点击一次屏幕,确保页面的展示
time.sleep(2)
self.scroll() # 滑动
if __name__ == '__main__':
action = DouyinAction(nums=5)
action.main()