appium python自动化代码运行douyin

#!/usr/bin/python

# -*- coding=utf-8 -*-

from os import sys

sys.path.append("..")

from imp import reload

reload(sys)

import time

from androguard.core.bytecodes.apk import APK

from appium import webdriver

 

from selenium.webdriver.support.ui import WebDriverWait

 

def get_page_size():

  x = driver.get_window_size()['width']

  y = driver.get_window_size()['height']

  return (x,y)

 

appPackage APK(app, False, "r").get_package()

  appActivity APK(app, False, "r").get_main_activity()

  desired_caps = { 'platformName': platformName, 'platformVersion':platformVersion, 'deviceName': '835c6ae1',

          'appPackage':appPackage,'appActivity':appActivity,'automationName': 'flutter',"skipServerInstallation": True} 

driver = webdrriver.Remote("http://localhost:4723/wb/hub",desired_caps )

try:

  if WebDriverWait(wait,10).until(lambda x:x .find_element_by_id("com.ss.android.ugc.ameme:id/c5h")):

    driver.find_element_by_id("com.ss.android.ugc.ameme:id/c5h")).click()

except:

  pass

if WebDriverWait(wait,5).until(lambda x:x .find_element_by_id("com.ss.android.ugc.ameme:id/et_search_kw")):

  driver.find_element_by_id("com.ss.android.ugc.ameme:id/et_search_kw")).click()

  driver.find_element_by_id("com.ss.android.ugc.ameme:id/et_search_kw")).send_keys("美女")

driver.find_element_by_id("com.ss.android.ugc.ameme:id/ldp")).click()

time.sleep(3)

 

L= get_page_size()

x1 = int(L[0]*0.5) #将光标放置屏幕中间

y1 = int(L[0]*0.9) 

y2 = int(L[0]*1.5)

while True:

  driver.swipe(x1,y1,x1,y2)

  if '没有更多了' in driver.page_source:

    break

 

 

#if WebDriverWait(wait,5).until(lambda x:x .find_element_by_id("com.ss.android.ugc.ameme:id/ldp")):

#  driver.find_element_by_xpath("//android.view.View[@content-desc=[‘靓女’]]")).click()

 

 

posted @ 2023-01-16 21:08  先定一个小目标  阅读(244)  评论(0)    收藏  举报