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