Browse Source

再次修复了一些bug

Shellmiao 4 years ago
parent
commit
9198cdde54
5 changed files with 43 additions and 27 deletions
  1. 15 10
      VerificationCode/mcbbs/SignIn.py
  2. 1 1
      VerificationCode/mcbbs/reply.py
  3. 1 1
      VerificationCode/ttshitu.py
  4. 1 1
      loginTools/login.py
  5. 25 14
      start.py

+ 15 - 10
VerificationCode/mcbbs/SignIn.py

@@ -15,16 +15,21 @@ def main_sign_in(driver):
 
 
 def sign_in_vc(driver):
-    image = get_image(driver)
-    image = image.convert('RGB')
-    image.save('D:\\同步文件\\课程文件\文档\\mcbbs搞事\\AutoTool\\VerificationCode\\image.jpg')
-    img_path = 'D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg'
-    result, rid = base64_api(uname='Shellmiao', pwd='sBif.9MMF8Pa', img=img_path)
-    print(result)
-    if click_vc_words(driver, get_points(result), rid):
-        print("打码成功")
-    else:
-        print("打码失败")
+    while True:
+        image = get_image(driver)
+        image = image.convert('RGB')
+        image.save('D:\\同步文件\\课程文件\文档\\mcbbs搞事\\AutoTool\\VerificationCode\\image.jpg')
+        img_path = 'D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg'
+        result, rid = base64_api(uname='Shellmiao', pwd='sBif.9MMF8Pa', img=img_path)
+        if not rid:
+            continue
+        else:
+            print(result)
+            if click_vc_words(driver, get_points(result), rid):
+                print("打码成功")
+            else:
+                print("打码失败")
+            break
 
 
 def get_points(result):

+ 1 - 1
VerificationCode/mcbbs/reply.py

@@ -51,7 +51,7 @@ def get_reply_content(driver):
             i = i - 1
         else:
             content = element.text
-            if '发表于' not in content:
+            if '发表于' not in content and '本贴最后由' not in content:
                 return content
             else:
                 i = i - 1

+ 1 - 1
VerificationCode/ttshitu.py

@@ -13,7 +13,7 @@ def base64_api(uname, pwd, img):
     if result['success']:
         return result["data"]["result"], result["data"]["id"]
     else:
-        return result["message"], result["data"]
+        return result["message"], result["success"]
 
 
 def error_report(rid):

+ 1 - 1
loginTools/login.py

@@ -27,7 +27,7 @@ def login(driver, cookie_path):
         return True
     else:
         if '空间已被锁定无法访问' in element.text:
-            print('被禁言')
+            print(cookie_path + '被禁言')
             return False
         else:
             return True

+ 25 - 14
start.py

@@ -5,7 +5,7 @@ from VerificationCode.mcbbs.task import get_new_tasks, complete_tasks
 from selenium import webdriver
 from loginTools.login import login
 from loginTools.include_all_cookies import include_all_cookies
-from selenium.common.exceptions import NoSuchWindowException, NoSuchElementException
+from selenium.common.exceptions import NoSuchWindowException, NoSuchElementException, WebDriverException
 import time
 import threading
 import random
@@ -30,13 +30,14 @@ def main_reply():
 
 
 def one_reply():
-    while True:
-        try:
-            driver = webdriver.Chrome()
-            cookies = include_all_cookies()
-            for cookie_path in cookies:
+    cookies = include_all_cookies()
+    for cookie_path in cookies:
+        while True:
+            try:
+                driver = webdriver.Chrome()
                 if not login(driver, cookie_path):
-                    continue
+                    driver.quit()
+                    break
                 time.sleep(10)
                 r = random.randint(1, 50)
                 r = str(r)
@@ -49,11 +50,15 @@ def one_reply():
                     r = str(r)
                     reply(driver, 'https://www.mcbbs.net/forum-mod-' + r + '.html')
                     i = i - 1
-            driver.quit()
-        except NoSuchWindowException:
-            continue
-        else:
-            break
+                driver.quit()
+            except NoSuchWindowException:
+                print('except NoSuchWindowException')
+                continue
+            except WebDriverException:
+                print('except WebDriverException')
+                continue
+            else:
+                break
 
 
 def main_tasks_and_sign():
@@ -75,8 +80,14 @@ def get_tasks_and_sign_in(driver):
             for cookie_path in cookies:
                 if not login(driver, cookie_path):
                     continue
-                main_sign_in(driver)
-                get_new_tasks(driver)
+                while True:
+                    try:
+                        main_sign_in(driver)
+                        get_new_tasks(driver)
+                    except WebDriverException:
+                        continue
+                    else:
+                        break
         except NoSuchElementException:
             continue
         else: