def article(cookies, a_log, each): if each[0] < 6 or each[3] < 8: driver_article = mydriver.Mydriver(nohead=nohead) driver_article.get_url("https://www.xuexi.cn/notFound.html") driver_article.set_cookies(cookies) links = get_links.get_article_links() try_count = 0 while True: if each[0] < 6 and try_count < 10: a_num = 6 - each[0] for i in range(a_log, a_log + a_num): driver_article.get_url(links[i]) time.sleep(random.randint(5, 15)) for j in range(120): if random.random() > 0.5: driver_article.go_js('window.scrollTo(0, document.body.scrollHeight/120*{})'.format(j)) print("\r文章学习中,文章剩余{}篇,本篇剩余时间{}秒".format(a_log + a_num - i, 120 - j), end="") time.sleep(1) driver_article.go_js('window.scrollTo(0, document.body.scrollHeight)') total, each = show_score(cookies) if each[0] >= 6: print("检测到文章数量分数已满,退出学习") break a_log += a_num else: with open("./user/{}/a_log".format(uname), "w", encoding="utf8") as fp: fp.write(str(a_log)) break try_count = 0 while True: if each[3] < 6 and try_count < 10: num_time = 60 driver_article.get_url(links[a_log-1]) time.sleep(random.randint(5, 15)) remaining = (6 - each[3]) * 4 * num_time for i in range(remaining): if random.random() > 0.5: driver_article.go_js( 'window.scrollTo(0, document.body.scrollHeight/{}*{})'.format(remaining, i)) print("\r文章时长学习中,文章总时长剩余{}秒".format(remaining - i), end="") time.sleep(1) if i % (120) == 0 and i != remaining: total, each = show_score(cookies) if each[3] >= 6: print("检测到文章时长分数已满,退出学习") break driver_article.go_js('window.scrollTo(0, document.body.scrollHeight)') total, each = show_score(cookies) else: break if try_count < 10: print("文章学习完成") else: print("文章学习出现异常,请检查用户名下a_log文件记录数") driver_article.quit() else: print("文章之前学完了")
def read_articles(): """阅读文章""" j = 0 links = get_links.get_article_links() random.shuffle(links) for link in random.sample(links, 20): browser.get(link) for i in range(0, 2000, 100): js_code = "var q=document.documentElement.scrollTop=" + str(i) browser.execute_script(js_code) time.sleep(1) for i in range(2000, 0, -100): js_code = "var q=document.documentElement.scrollTop=" + str(i) browser.execute_script(js_code) time.sleep(1) #time.sleep(20) j += 1 print(j, browser.title) print("阅读文章完毕\n")
def article(driver_article, a_log, myscores): # if each[0] < 6 or each[3] < 8: # if deach[0] < 2: if myscores['有效浏览'] < myscores['有效浏览目标'] or myscores['文章时长'] < myscores['文章时长目标'] or myscores['阅读文章'] < myscores['阅读文章目标']: # driver_article = mydriver.Mydriver(nohead=nohead) # driver_article.get_url("https://www.xuexi.cn/notFound.html") # driver_article.set_cookies(cookies) links = get_links.get_article_links() try_count = 0 lifetime = 0 while True: # if each[0] < 6 and try_count < 10: # if deach[0] < 2 and try_count < 20: if myscores['有效浏览'] < myscores['有效浏览目标'] or myscores['阅读文章'] < myscores['阅读文章目标'] and try_count < 10: # a_num = 6 - each[0] # a_num = 20 - deach[0]*10-deach[3]%10 # 检查点点通还差多少条 # 检查点点通还差多少条 # a_num_total = min(myscores['有效浏览目标'] - myscores['有效浏览'], 12) # a_num = min(random.randint(8, 12), a_num_total) a_num = min(myscores['有效浏览目标'] - myscores['有效浏览'], 12) # print(a_num) for i in range(a_log, a_log + a_num): driver_article.get_url(links[i]) print(i, driver_article.get_title()) # time.sleep(random.randint(2, 5)) # 学习时长 # t = random.randint(30, 40) t = (myscores['文章时长目标'] - myscores['文章时长']) * 2 * 60 // a_num # a_num_total if t < 16: t = random.randint(10, 15) else: t = random.randint(t-2, t+8) t = random.randint(15, 45) lifetime += t # print("时长是:{}".format(t)) for j in range(t): if random.random() > 0.5: driver_article.go_js('window.scrollTo(0, (document.body.scrollHeight-1000)/{}*{})'.format(t, j)) print("\r文章学习中,文章剩余{}篇,本篇时长{}秒,剩余时间{}秒".format(a_log + a_num - i, t, t - j-1), end="") time.sleep(1) print('') # lou # driver_article.go_js('window.scrollTo(0, document.body.scrollHeight)') myscores.update(show_scorenew(driver_article)) #if each[0] >= 6: # if deach[0] >= 2: ''' if myscores['有效浏览'] >= numtarget and myscores['阅读文章'] >= myscores['阅读文章目标']: print("检测到文章数量分数已满,退出学习") break ''' a_log += a_num else: with open("./user/{}/a_log".format(myscores['userId']), "w", encoding="utf8") as fp: fp.write(str(a_log)) print("检测到文章数量分数已满,退出学习") break try_count = 0 while True: if myscores['文章时长'] < myscores['文章时长目标'] and try_count < 10: num_time = 60 driver_article.get_url(links[a_log-1]) # time.sleep(random.randint(2, 5)) remaining = random.randint(15, 30) remaining += (myscores['文章时长目标'] - myscores['文章时长'] - 1) * 2 * num_time print("剩下时长是:{}".format(remaining)) lifetime += remaining for i in range(remaining): if random.random() > 0.5: driver_article.go_js( 'window.scrollTo(0, (document.body.scrollHeight-800)/{}*{})'.format(remaining, i)) print("\r文章时长学习中,文章总时长剩余{}秒".format(remaining - i - 1), end="") time.sleep(1) ''' if i % (120) == 0 and i != remaining: total, each, dtotal, deach, myscores = show_score(driver_article.get_cookies()) if myscores['文章时长'] >= timetarget: print("检测到文章时长分数已满,退出学习") break ''' print('') # driver_article.go_js('window.scrollTo(0, document.body.scrollHeight)') myscores.update(show_scorenew(driver_article)) else: print("检测到文章时长分数已满,退出学习") break if try_count < 10: print("文章学习完成") else: print("文章学习出现异常,请检查用户名下a_log文件记录数") # driver_article.quit() print("学习文章共用时长:{}".format(lifetime)) else: print("文章之前学完了")
def article(userId, cookies, article_pointer, scores): try: if scores["article_num"] < const.article_num_all or scores[ "article_time"] < const.article_time_all: # driver_article = Mydriver(nohead=nohead) driver_article = Mydriver(nohead=True) # def article_stop_function(): # driver_article.quit() # threads.regist_stop_function(article_stop_function) driver_article.get_url("https://www.xuexi.cn/notFound.html") driver_article.set_cookies(cookies) links = get_links.get_article_links() try_count = 0 readarticle_time = 0 while True: if scores[ "article_num"] < const.article_num_all and try_count < 10: article_remain = const.article_num_all - scores[ "article_num"] for i in range(article_pointer, article_pointer + article_remain): driver_article.get_url(links[i]) readarticle_time = 60 + random.randint(5, 15) for j in range(readarticle_time): if random.random() > 0.5: driver_article.go_js( 'window.scrollTo(0, document.body.scrollHeight/120*{})' .format(j)) print("\r文章数量学习中,文章剩余{}篇,本篇剩余时间{}秒".format( article_pointer + article_remain - i, readarticle_time - j), end="") time.sleep(1) driver_article.go_js( 'window.scrollTo(0, document.body.scrollHeight)') total, scores = show_score(cookies) if scores["article_num"] >= const.article_num_all: print("检测到文章数量分数已满,退出学习") break article_pointer += article_remain else: user.save_article_index(userId, article_pointer) break try_count = 0 while True: if scores[ "article_time"] < const.article_time_all and try_count < 10: num_time = 60 driver_article.get_url(links[article_pointer - 1]) remaining = (const.article_time_all - scores["article_time"]) * 1 * num_time for i in range(remaining): if random.random() > 0.5: driver_article.go_js( 'window.scrollTo(0, document.body.scrollHeight/{}*{})' .format(remaining, i)) print("\r文章时长学习中,文章总时长剩余{}秒".format(remaining - i), end="") time.sleep(1) if i % (60) == 0 and i != remaining: total, scores = show_score(cookies) if scores["article_time"] >= const.article_time_all: print("检测到文章时长分数已满,退出学习") break driver_article.go_js( 'window.scrollTo(0, document.body.scrollHeight)') total, scores = show_score(cookies) else: break if try_count < 10: print("文章学习完成") else: print("文章学习出现异常,请检查 user/article_video_index.json 文件记录") driver_article.quit() else: print("文章之前学完了") except Exception as e: print(color.red("文章学习检测到异常:" + str(e)))