def reconnect(self): dr = self.driver time.sleep(2) #切换VPN button_connect = WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id("org.wuji:id/exit_vpn")) button_connect.click() time.sleep(1) # try: # dr.find_element_by_name("正在初始化数据").click() # time.sleep(5) # except NoSuchElementException: # pass # try: # dr.find_element_by_name("启动失败") # button_connect.click() # time.sleep(5) # except NoSuchElementException: # pass #检测连接成功 try: WebDriverWait(dr, 15).until( lambda d: d.find_element_by_id("com.miui.home:id/cell_layout")) except TimeoutException: return self.onConnectTimeout self.reconnect_times = 0 return self.exit
def modify_data_suiji(self): dr = self.driver dr.find_element_by_name("修改数据").click() time.sleep(1) xpath = "//android.widget.Spinner/android.widget.TextView" spinners = dr.find_elements_by_xpath(xpath) self.chanel = spinners[0].text self.remain_day = spinners[1].text.split(":")[1] #获取imei edts = dr.find_elements_by_class_name("android.widget.EditText") if edts.__len__() > 6: oldimei = edts[9].text else: oldimei = edts[0].text if self.remain_day == '1': # dr.find_element_by_name("网络获取").click() dr.find_element_by_name("随机数据").click() elif self.remain_day == '0': dr.press_keycode(4) time.sleep(60) return self.modify_data else: dr.find_element_by_name("本地获取").click() try: save = WebDriverWait( dr, 15).until(lambda d: d.find_element_by_name("保存")) save.click() except TimeoutException: self.try_count += 1 if self.try_count <= 3: dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) return self.modify_data self.try_count = 0 dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) dr.find_element_by_name("网络获取失败,退出重新调VPN") time.sleep(1) #获取imei edts = dr.find_elements_by_class_name("android.widget.EditText") if edts.__len__() > 6: self.imei = edts[9].text else: self.imei = edts[0].text print('imei:' + self.imei) # if oldimei == self.imei: # dr.press_keycode(4) # print("留存已跑完挂机300s") # time.sleep(300) # return self.modify_data dr.press_keycode(4) time.sleep(1) return self.do_task
def uuwise(self): dr = self.driver dr.press_keycode(3) time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("UUWiseDemo")).click() time.sleep(1) try: dr.find_element_by_name("查分") dr.press_keycode(4) time.sleep(1) except NoSuchElementException: pass btlogin = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/btn_login")) edtsuser = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/et_loginname")) edtspwd = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/et_loginpwd")) uuuser = '******' uupwd = 'meiriq2014' if edtsuser.text == uuuser and edtspwd.text == uupwd: pass else: edtsuser.send_keys(uuuser) time.sleep(1) edtspwd.send_keys(uupwd) time.sleep(1) btlogin.click() screenshotpath = dr.find_element_by_id("com.example.uuwisedemo:id/et_path") for x in range(10): screenshotpath.click() time.sleep(0.5) dr.press_keycode(123) time.sleep(0.5) for i in range(40): dr.press_keycode(67) if screenshotpath.text == "路径": break screenshotpath.send_keys('/sdcard/captcha.png') time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/btn_recognize")).click() time.sleep(1) captcha = None try: msg = WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id("com.example.uuwisedemo:id/txt_code")) match = re.search(r'验证码:\d+\|([0-9a-zA-Z]+)', msg.text) if match: captcha = match.group(1) else: captcha = None except: pass dr.press_keycode(4) time.sleep(1) dr.press_keycode(82) time.sleep(2) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name(self.appname)).click() return captcha
def modify_data(self): dr = self.driver btmodify = WebDriverWait(dr, 30).until(lambda d: d.find_elements_by_class_name("android.widget.ImageView")) btmodify[1].click() time.sleep(1) dr.find_element_by_name("从网络获取数据").click() save = WebDriverWait(dr, 30).until(lambda d: d.find_element_by_name("保存")) save.click() time.sleep(1) dr.press_keycode(4) time.sleep(1) return self.do_toolbox_task
def close_connection(self): dr = self.driver if self.city == "广州": server_ip = ["183.47.6.115", "gzjsq51.2288.org", "gzjsq86.2288.org", "zhjsq77.2288.org", "zhjsq78.2288.org", "hyjsq81.2288.org", "szjsq85.2288.org", "hzjsq80.2288.org", "dgjsq50.2288.org", "mzjsq98.2288.org"] try: WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("已连接")).click() time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("断开连接")).click() time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.android.settings:id/detail_arrow")).click() time.sleep(1) edts = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.android.settings:id/server")) edts.click() dr.press_keycode(123) time.sleep(1) time.sleep(0.5) for i in range(30): dr.press_keycode(67) edts.send_keys(choice(server_ip)) time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("确定")).click() time.sleep(1) print("thats ok") except TimeoutException as e: print("in else") WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.android.settings:id/detail_arrow")).click() time.sleep(1) edts = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.android.settings:id/server")) edts.click() dr.press_keycode(123) time.sleep(1) time.sleep(0.5) for i in range(30): dr.press_keycode(67) edts.send_keys(choice(server_ip)) time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("确定")).click() time.sleep(1) else: try: WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("已连接")).click() time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("断开连接")).click() time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_name("PPTP VPN")).click() time.sleep(1) print("thats ok") except TimeoutException as e: print("in else") dr.find_element_by_class_name("android.widget.RadioButton").click() time.sleep(1) return self.reconnect
def modify_data(self): dr = self.driver dr.find_element_by_name("修改数据").click() time.sleep(1) xpath = "//android.widget.Spinner/android.widget.TextView" spinners = dr.find_elements_by_xpath(xpath) self.remain_day = spinners[1].text.split(":")[1] #获取旧imei imei_xpath = "//android.widget.LinearLayout[@resource-id='com.meiriq.xposehook:id/til_device_id']/android.widget.EditText" imei = dr.find_element_by_xpath(imei_xpath) oldimei = imei.text if self.remain_day == '1': dr.find_element_by_name("网络获取").click() elif self.remain_day == '0': dr.press_keycode(4) time.sleep(60) return self.modify_data else: dr.find_element_by_name("本地获取").click() try: save = WebDriverWait( dr, 15).until(lambda d: d.find_element_by_name("保存")) save.click() except TimeoutException: self.try_count += 1 if self.try_count <= 3: dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) return self.modify_data self.try_count = 0 dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) raise Exception("网络获取数据失败重新开始") time.sleep(1) #获取新imei self.imei = imei.text print('imei:' + self.imei) #检测留存是否已做完 if oldimei == self.imei: dr.press_keycode(4) print("留存已跑完挂机300s") time.sleep(300) raise Exception("挂机完成重新开始") dr.press_keycode(4) time.sleep(1) return self.do_task
def enter_vpn(self): dr = self.driver dr.press_keycode(3) # back to Home time.sleep(1) dr.find_element_by_name("无极VPN").click() time.sleep(1) try: dr.find_element_by_name("确定").click() time.sleep(1) except NoSuchElementException: pass #检测是否已登录 try: button_login = WebDriverWait(dr, 5).until( lambda d: d.find_element_by_id("org.wuji:id/loginbutton")) # edts = WebDriverWait(dr, 5).until(lambda d: d.find_elements_by_class_name("android.widget.EditText")) # if edts[0].text == "请输入用户名": # edts[0].send_keys("") # time.sleep(0.5) # edts[1].send_keys("") # time.sleep(0.5) automin = dr.find_element_by_id("org.wuji:id/cb_automin") if automin.get_attribute("checked") == 'false': automin.click() time.sleep(0.5) button_login.click() try: WebDriverWait( dr, 5).until(lambda d: d.find_element_by_name("确定")).click() time.sleep(5) return self.enter_vpn except TimeoutException: pass except TimeoutException: pass try: WebDriverWait(dr, 15).until( lambda d: d.find_element_by_id("org.wuji:id/exit_vpn")) except TimeoutException: dr.press_keycode(3) time.sleep(1) dr.press_keycode(3) time.sleep(1) killapp("org.wuji") time.sleep(1) return self.enter_vpn() return self.reconnect
def modify_data(self): dr = self.driver #使用GPS模拟 gps = dr.find_element_by_id("com.rong.xposed.fakelocation:id/gps_switch") if gps.text == "关闭": gps.click() time.sleep(0.5) #输入经度 lat = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.rong.xposed.fakelocation:id/edit_lat")) for x in range(10): lat.click() time.sleep(0.5) dr.press_keycode(123) time.sleep(0.5) for i in range(40): dr.press_keycode(67) if lat.text == "": break lat.send_keys(self.latnum) time.sleep(0.5) #输入纬度 lot = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id("com.rong.xposed.fakelocation:id/edit_lot")) for x in range(10): lot.click() time.sleep(0.5) dr.press_keycode(123) time.sleep(0.5) for i in range(40): dr.press_keycode(67) if lot.text == "": break lot.send_keys(self.lotnum) time.sleep(1) #即时更新 dr.find_element_by_id("com.rong.xposed.fakelocation:id/chk_instant_update").click() time.sleep(1) print("修改定位完成") #退出 dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) return self.exit
def after_signup(self): dr = self.driver WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/tv_user_nickname")).click() time.sleep(1) #输入昵称 name = WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/et_nickname")) name.click() time.sleep(0.5) dr.press_keycode(123) time.sleep(0.5) for i in range(10): dr.press_keycode(67) name.send_keys(self.get_filemessage("name.txt")) time.sleep(1) #选择性别 if random.randint(0, 1): WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/tv_gender")).click() time.sleep(1) dr.swipe(300, 1180, 300, 1100) WebDriverWait( dr, 15).until(lambda d: d.find_element_by_name("确定")).click() time.sleep(1) #选择年龄 if not random.randint(0, 4): WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/tv_age")).click() time.sleep(1) self.swipes(300, 1180, 300, 1100, random.randint(17, 30), 1, 1) WebDriverWait( dr, 15).until(lambda d: d.find_element_by_name("确定")).click() time.sleep(1) #保存信息按钮 WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/ibtn_right")).click() time.sleep(10) #检测信息保存完毕跳转页面 WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/rbtn_personal_center")) #选择头像 if not random.randint(0, 9): WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/chiv_user_header")).click() time.sleep(1) WebDriverWait( dr, 5).until(lambda d: d.find_element_by_name("相册")).click() time.sleep(1) WebDriverWait( dr, 5).until(lambda d: d.find_element_by_name("文件管理")).click() time.sleep(1) WebDriverWait( dr, 15).until(lambda d: d.find_element_by_name("1")).click() time.sleep(1) WebDriverWait(dr, 15).until( lambda d: d.find_element_by_name("1touxiang")).click() time.sleep(1) for i in range(random.randint(0, 80)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600)) time.sleep(1) time.sleep(5) self.select_one_by_id("com.android.fileexplorer:id/file_image") time.sleep(1) WebDriverWait(dr, 15).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/btn_done")).click() time.sleep(1) #检测信息保存完毕跳转页面 WebDriverWait(dr, 60).until(lambda d: d.find_element_by_id( "com.paoword.www.paoword:id/rbtn_personal_center")) self.issign = True #记录帐号密码 try: with open('/sdcard/1/user%s.log' % self.appname_en, 'a') as f: f.write( '\nimei:%s,%s,%s (time %s.%s %s:%s:%s)' % (self.imei, self.phone, self.pwd, time.localtime().tm_mon, time.localtime().tm_mday, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) except: with open( 'D:/brush/slave/scripts/doc/user%s.log' % self.appname_en, 'a') as f: f.write( '\nimei:%s,%s,%s (time %s.%s %s:%s:%s)' % (self.imei, self.phone, self.pwd, time.localtime().tm_mon, time.localtime().tm_mday, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) time.sleep(1) return self.do
def menu1(self): dr = self.driver try: try: WebDriverWait(dr, 5).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/tv_info")).click() time.sleep(1) except TimeoutException: pass looknum = random.randint(2, 5) for _ in range(looknum): for i in range(random.randint(0, 2)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600)) time.sleep(random.randint(2, 5)) self.select_one_by_id("com.tujiaapp.tujia:id/item_tv_title") time.sleep(random.randint(5, 10)) for i in range(random.randint(1, 4)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 600)) time.sleep(random.randint(1, 2)) #点赞 if not random.randint(0, 9): try: WebDriverWait( dr, 5).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/ll_heart")).click() time.sleep(1) except TimeoutException: pass #收藏 if not random.randint(0, 9): try: WebDriverWait( dr, 5).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/iv_like")).click() time.sleep(1) except TimeoutException: pass #评论 if not random.randint(0, 19): try: content = WebDriverWait( dr, 5).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/tv_comment_count")) match = re.search(r'(\d+)评论', content.text) contentnum = match.group(1) if int(contentnum) > 5: content.click() time.sleep(5) self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(2, 10), 2, 2) time.sleep(2) contenttext = WebDriverWait( dr, 30).until(lambda d: d.find_elements_by_id( "com.tujiaapp.tujia:id/tv_content")) comtext = contenttext[random.randint( 0, contenttext.__len__() - 1)].text WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/tv_to_comment") ).click() time.sleep(1) edit = WebDriverWait(dr, 30).until( lambda d: d.find_element_by_class_name( "android.widget.EditText")) edit.send_keys(comtext) time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/view_comment_sure") ).click() time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.tujiaapp.tujia:id/iv_close_fragment") ).click() time.sleep(1) except TimeoutException: pass dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) self.readnum -= 1 self.ismenu1 = False except Exception as e: print("error in menu1") return self.exception_returnapp() return self.do
def change_date_dir(self): dr = self.driver for x in range(2): try: dr.press_keycode(4) time.sleep(1) WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id( "com.soft.apk008v:id/main_centerImg")).click() time.sleep(1) break except TimeoutException: pass if time.localtime().tm_hour == 0: self.add_remain_data() #激活 if self.frist_day: dr.find_element_by_name("随机生成").click() try: save = WebDriverWait( dr, 60).until(lambda d: d.find_element_by_name("保存")) self.imei = dr.find_element_by_class_name( "android.widget.EditText").text save.click() time.sleep(1) #确定根据日期分类 try: WebDriverWait(dr, 2).until( lambda d: d.find_element_by_name("确定")).click() time.sleep(1) except TimeoutException: pass except TimeoutException: #获取数据失败..网络出错 dr.press_keycode(4) # keypress back time.sleep(1) try: WebDriverWait(dr, 2).until( lambda d: d.find_element_by_name("确定")).click() time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) except TimeoutException: pass print("Mode Switch!@") return self.onEnterException #留存 else: dr.find_element_by_id( "com.soft.apk008v:id/menu_remainControl").click() ## 留存控制按键 time.sleep(1) dr.find_element_by_name("下一条数据").click() time.sleep(1) try: save = dr.find_element_by_name("保存") # 若到达100%则无法返回上一个页面 self.imei = dr.find_element_by_class_name( "android.widget.EditText").text save.click() except Exception as e: self.frist_day = 1 dr.press_keycode(4) # keypress back time.sleep(1) return self.modify_data return self.exit
def modify_data_dingwei(self): dr = self.driver for x in range(2): try: dr.press_keycode(4) time.sleep(1) WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id( "com.soft.apk008v:id/main_centerImg")).click() time.sleep(1) break except TimeoutException: pass #添加留存记录 if time.localtime().tm_hour == 0: self.add_remain_data() # 激活 if self.frist_day: dr.find_element_by_name("从网络获取数据").click() try: WebDriverWait(dr, 60).until(lambda d: d.find_element_by_name("保存")) self.imei = dr.find_element_by_class_name( "android.widget.EditText").text #定位 dr.swipe(300, 1000, 300, 200) time.sleep(1) dr.swipe(300, 1000, 300, 200) time.sleep(1) WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id( "com.soft.apk008v:id/set_map_buttonSetJiZhan")).click() time.sleep(1) WebDriverWait(dr, 30).until(lambda d: d.find_element_by_id( "com.soft.apk008Tool:id/jizhanNew_button_getData")).click( ) time.sleep(1) nextpage = WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.soft.apk008Tool:id/jizhanNew_buttonNextPage")) for x in range(random.randint(0, 10)): nextpage.click() time.sleep(1) for x in range(random.randint(0, 2)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(300, 500)) time.sleep(1) selectone = WebDriverWait( dr, 15).until(lambda d: d.find_elements_by_id( "com.soft.apk008Tool:id/jizhan_new_item_name")) selectone[random.randint(0, selectone.__len__() - 1)].click() time.sleep(2) # dr.swipe(300, 450, 300, 1100) # time.sleep(1) # dr.swipe(300, 450, 300, 1100) # time.sleep(1) WebDriverWait( dr, 60).until(lambda d: d.find_element_by_name("保存")).click() time.sleep(1) try: WebDriverWait(dr, 2).until( lambda d: d.find_element_by_name("确定")).click() time.sleep(1) except TimeoutException: pass except TimeoutException: dr.press_keycode(4) # keypress back time.sleep(0.5) try: WebDriverWait(dr, 5).until( lambda d: d.find_element_by_name("确定")).click() time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) except TimeoutException: pass print("Mode Switch!@") return self.onEnterException #留存 else: dr.find_element_by_id( "com.soft.apk008v:id/menu_remainControl").click() ## 留存控制按键 time.sleep(1) dr.find_element_by_name("下一条数据").click() time.sleep(1) try: save = dr.find_element_by_name("保存") # 若到达100%则无法返回上一个页面 self.imei = dr.find_element_by_class_name( "android.widget.EditText").text save.click() except Exception as e: if self.change: self.frist_day = 1 dr.press_keycode(4) # keypress back time.sleep(1) return self.modify_data_dingwei else: self.frist_day = 2 dr.press_keycode(4) # keypress back time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) return self.exit_008() return self.do_toolbox_task
def menu2(self): dr = self.driver try: for _ in range(random.randint(1, 2)): #随机滑动 for x in range(random.randint(1, 3)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(400, 600)) time.sleep(random.randint(2, 5)) #随机选择新闻查看 selectone = WebDriverWait( dr, 10).until(lambda d: d.find_elements_by_id( choice([ "com.shwatch.news:id/news_1smallitem_layout", "com.shwatch.news:id/section_newsitem" ]))) selectone[random.randint(0, selectone.__len__() - 1)].click() time.sleep(random.randint(5, 10)) #随机滑动 for x in range(random.randint(2, 4)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(400, 600)) time.sleep(random.randint(2, 10)) #收藏 if random.randint(0, 4) == 0: try: WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/collection_btn")).click() time.sleep(1) except TimeoutException: pass #喜欢 if random.randint(0, 4) == 0: try: WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/news_praise")).click() time.sleep(1) except TimeoutException: pass #评论 if random.randint(0, 9) == 0 and self.issign: try: contentnum = WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/comment_account")) if int(contentnum.text) > 3: contentnum.click() time.sleep(5) self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(0, 3), 2, 5) contenttext = WebDriverWait( dr, 30).until(lambda d: d.find_elements_by_id( "com.shwatch.news:id/enter_ticket")) time.sleep(1) comtext = contenttext[random.randint( 0, contenttext.__len__() - 1)].text WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/write_comment") ).click() time.sleep(1) edit = WebDriverWait(dr, 30).until( lambda d: d.find_element_by_class_name( "android.widget.EditText")) edit.send_keys(comtext) time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/send_message_btn") ).click() time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/btn_callback")).click( ) time.sleep(1) except TimeoutException: pass dr.press_keycode(4) time.sleep(1) self.readnum -= 1 self.ismenu2 = False except Exception as e: print("error in menu2") return self.exception_returnapp() return self.do
def do(self): dr = self.driver try: while self.readnum: print("剩下阅读次数:%s" % self.readnum) #随机滑动 self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(1, 3), 2, 5) #随机选择新闻查看 selectone = WebDriverWait( dr, 10).until(lambda d: d.find_elements_by_id( choice([ "com.shwatch.news:id/homepage_smallText1", "com.shwatch.news:id/homepage_smallText2", "com.shwatch.news:id/homepage_bigText" ]))) selectone[random.randint(0, selectone.__len__() - 1)].click() time.sleep(random.randint(5, 10)) #随机滑动 for x in range(random.randint(1, 4)): dr.swipe(300, random.randint(800, 1000), 300, random.randint(400, 600)) time.sleep(random.randint(2, 10)) #收藏 if random.randint(0, 4) == 0: try: WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/collection_btn")).click() time.sleep(1) except TimeoutException: pass #喜欢 if random.randint(0, 4) == 0: try: WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/news_praise")).click() time.sleep(1) except TimeoutException: pass #评论 if random.randint(0, 9) == 0 and self.issign: try: contentnum = WebDriverWait( dr, 10).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/comment_account")) if int(contentnum.text) > 3: contentnum.click() time.sleep(5) self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(0, 3), 2, 5) contenttext = WebDriverWait( dr, 30).until(lambda d: d.find_elements_by_id( "com.shwatch.news:id/enter_ticket")) time.sleep(1) edit = WebDriverWait(dr, 30).until( lambda d: d.find_element_by_class_name( "android.widget.EditText")) edit.send_keys(contenttext[random.randint( 0, contenttext.__len__() - 1)].text) time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/send_message_btn") ).click() time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.shwatch.news:id/back_img")).click() time.sleep(1) except TimeoutException: pass dr.press_keycode(4) time.sleep(1) self.readnum -= 1 return self.do except TimeoutException: print("查找菜单出错") return self.exception_returnapp() print("阅览完毕") return self.ends
def menu4(self): dr = self.driver try: self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(1, 3), 2, 5) self.select_one_by_id( "com.yixia.videoeditor:id/discovery_topic_title") time.sleep(random.randint(5, 10)) for _ in range(random.randint(1, 3)): self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(0, 2), 2, 5) self.select_one_by_id("com.yixia.videoeditor:id/des") time.sleep(random.randint(10, 15)) #关注 if not random.randint(0, 4): try: WebDriverWait( dr, 5).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/relation")).click() time.sleep(1) WebDriverWait( dr, 2).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/dialog_left_buton") ).click() time.sleep(1) except TimeoutException: pass time.sleep(random.randint(10, 15)) #赞 if not random.randint(0, 4): try: WebDriverWait( dr, 5 ).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/video_good_count_layout") ).click() time.sleep(1) except TimeoutException: pass time.sleep(random.randint(10, 15)) #评论 if not random.randint(0, 19) and self.issign: try: contentnum = WebDriverWait( dr, 10 ).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/feed_video_comment_count" )) if int(contentnum.text) > 10: contentnum.click() time.sleep(5) self.swipes(300, random.randint(800, 1000), 300, random.randint(400, 600), random.randint(2, 10), 2, 2) time.sleep(2) contenttext = WebDriverWait( dr, 30).until(lambda d: d.find_elements_by_id( "com.yixia.videoeditor:id/comment_content") ) comtext = contenttext[random.randint( 0, contenttext.__len__() - 1)].text WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/comment_input") ).click() time.sleep(1) edit = WebDriverWait(dr, 30).until( lambda d: d.find_element_by_class_name( "android.widget.EditText")) edit.send_keys(comtext) time.sleep(1) WebDriverWait( dr, 30).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/send_text") ).click() time.sleep(1) WebDriverWait( dr, 30 ).until(lambda d: d.find_element_by_id( "com.yixia.videoeditor:id/detail_title_back") ).click() time.sleep(1) except TimeoutException: pass time.sleep(random.randint(10, 15)) dr.press_keycode(4) time.sleep(1) dr.press_keycode(4) time.sleep(1) self.readnum -= 1 self.ismenu4 = False except Exception as e: print("error in menu4") return self.exception_returnapp() return self.do
def modify_data(self): dr = self.driver WebDriverWait(dr, 10).until(lambda d: d.find_element_by_id( "com.soft.apk008v:id/main_centerImg")).click() time.sleep(1) #0点增加留存记录 if time.localtime().tm_hour == 0 and time.localtime().tm_min < 15: self.add_remain_data() #激活 if self.frist_day: dr.find_element_by_name("从网络获取数据").click() try: save = WebDriverWait( dr, 60).until(lambda d: d.find_element_by_name("保存")) self.imei = dr.find_element_by_class_name( "android.widget.EditText").text save.click() time.sleep(1) #确定根据日期分类 try: dr.find_element_by_name("确定").click() time.sleep(1) except NoSuchElementException: pass dr.press_keycode(4) time.sleep(1) except TimeoutException: #获取数据失败..网络出错 dr.press_keycode(4) # keypress back time.sleep(1) try: dr.find_element_by_name("确定").click() time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) except NoSuchElementException: pass print("Mode Switch!@") return self.onEnterException #留存 else: dr.find_element_by_id( "com.soft.apk008v:id/menu_remainControl").click() ## 留存控制按键 time.sleep(1) dr.find_element_by_name("下一条数据").click() time.sleep(1) try: save = dr.find_element_by_name("保存") # 若到达100%则无法返回上一个页面 self.imei = dr.find_element_by_class_name( "android.widget.EditText").text save.click() dr.press_keycode(4) time.sleep(1) except Exception as e: if self.change: self.frist_day = 1 dr.press_keycode(4) # keypress back time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) return self.modify_data else: self.frist_day = 2 dr.press_keycode(4) # keypress back time.sleep(1) dr.press_keycode(4) # keypress back time.sleep(1) return self.exit_008() return self.do_toolbox_task