Browse Source

完成了对回复文本的检查,以及矿工茶馆的回复,大概开始使用了

Shellmiao 4 năm trước cách đây
mục cha
commit
d5a2b0d705
4 tập tin đã thay đổi với 150 bổ sung22 xóa
  1. 40 17
      VerificationCode/mcbbs/reply.py
  2. 103 0
      geckodriver.log
  3. 0 0
      loginTools/gui2.txt
  4. 7 5
      start.py

+ 40 - 17
VerificationCode/mcbbs/reply.py

@@ -1,37 +1,60 @@
 from selenium.webdriver.common.action_chains import ActionChains
+from selenium.common.exceptions import NoSuchElementException
 import random
 import time
 
 
-def reply(driver):
-    reply_page_url = get_reply_page_url(driver)
-    driver.get(reply_page_url)
-    content = get_reply_content(driver)
-    start_reply(driver, content)
+def reply(driver, url):
+    while True:
+        reply_page_url = get_reply_page_url(driver, url)
+        driver.get(reply_page_url)
+        content = get_reply_content(driver)
+        if not content == '#':
+            if start_reply(driver, content):
+                break
     time.sleep(2)
 
 
 # 进行回复动作
 def start_reply(driver, content):
-    print(content)
-    message = driver.find_element_by_id('vmessage')
-    ActionChains(driver).move_to_element(message).click().perform()
-    message.send_keys(content)
-    time.sleep(20)
-    element = driver.find_element_by_id('vreplysubmit')
-    ActionChains(driver).move_to_element(element).click().perform()
+    try:
+        message = driver.find_element_by_id('vmessage')
+    except NoSuchElementException:
+        return False
+    else:
+        ActionChains(driver).move_to_element(message).double_click().perform()
+        time.sleep(5)
+        message.send_keys(content)
+        print(content)
+        time.sleep(1)
+        element = driver.find_element_by_id('vreplysubmit')
+        ActionChains(driver).move_to_element(element).click().perform()
+        return True
 
 
 # 读取从上往下第二条评论的内容,并返回
 def get_reply_content(driver):
-    element = driver.find_element_by_xpath(
-        "//div[@id='postlist']/div[3]/table/tbody/tr/td[2]/div[2]/div/div/table/tbody/tr/td")
-    return element.text
+    i = 4
+    while i >= 0:
+        r = random.randint(3, 12)
+        r = str(r)
+        try:
+            element = driver.find_element_by_xpath(
+                "//div[@id='postlist']/div[" + r + "]/table/tbody/tr/td[2]/div[2]/div/div/table/tbody/tr/td")
+        except NoSuchElementException:
+            i = i - 1
+        else:
+            content = element.text
+            if '发表于' not in content:
+                return content
+            else:
+                i = i - 1
+    return '#'
 
 
 # 取得mod发布页面的最后一个页面的url
-def get_reply_page_url(driver):
-    driver.get('https://www.mcbbs.net/forum-mod-1.html')
+def get_reply_page_url(driver, url):
+    driver.get(url)
     r = random.randint(0, 24)
     r = str(r)
     element = driver.find_element_by_xpath("//form[@id='moderate']/table/tbody[last()-" + r + "]/tr/th/a[3]")

+ 103 - 0
geckodriver.log

@@ -2236,3 +2236,106 @@ JavaScript error: https://www.mcbbs.net/home.php?mod=task&do=view&id=11, line 25
 JavaScript error: https://www.mcbbs.net/home.php?mod=task&do=view&id=11, line 402: ReferenceError: A is not defined
 JavaScript error: https://www.mcbbs.net/home.php?mod=task&item=doing, line 258: ReferenceError: announcement is not defined
 JavaScript error: https://www.mcbbs.net/home.php?mod=task&item=doing, line 472: ReferenceError: A is not defined
+1613291116784	geckodriver	INFO	Listening on 127.0.0.1:13827
+1613291117386	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofilejfgU21"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613291122832	Marionette	INFO	Listening on port 13836
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613291123226	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613291123247	Marionette	ERROR	[15] No reply from Marionette:Register
+1613291194051	geckodriver	INFO	Listening on 127.0.0.1:13966
+1613291194569	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofileWMUnEf"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613291199222	Marionette	INFO	Listening on port 13975
+1613291199365	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613291199395	Marionette	ERROR	[15] No reply from Marionette:Register
+1613291295846	geckodriver	INFO	Listening on 127.0.0.1:14169
+1613291296432	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofile08eM8I"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613291301551	Marionette	INFO	Listening on port 14178
+1613291301752	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613291301766	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+console.log: WebExtensions: reset-default-search: No addons in our list are installed.
+1613292130489	geckodriver	INFO	Listening on 127.0.0.1:1031
+1613292131106	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofilepJKGjw"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613292137414	Marionette	INFO	Listening on port 1043
+1613292137505	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613292137537	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+console.log: WebExtensions: reset-default-search: No addons in our list are installed.
+1613292894828	geckodriver	INFO	Listening on 127.0.0.1:2009
+1613292895398	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofiletpplHo"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613292900526	Marionette	INFO	Listening on port 2018
+1613292900789	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613292900828	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293049661	geckodriver	INFO	Listening on 127.0.0.1:2334
+1613293050266	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofilePeoS9B"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293055968	Marionette	INFO	Listening on port 2343
+1613293056063	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293056091	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293204045	geckodriver	INFO	Listening on 127.0.0.1:2606
+1613293204634	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofileP6YWoE"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293210983	Marionette	INFO	Listening on port 2614
+1613293211106	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293211128	Marionette	ERROR	[18] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293425855	geckodriver	INFO	Listening on 127.0.0.1:2919
+1613293426448	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofileO36g40"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293432628	Marionette	INFO	Listening on port 2928
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293432760	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293432778	Marionette	ERROR	[15] No reply from Marionette:Register
+1613293538295	geckodriver	INFO	Listening on 127.0.0.1:3153
+1613293538880	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofileqTHy1f"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293543685	Marionette	INFO	Listening on port 3162
+1613293544125	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293544140	Marionette	ERROR	[15] No reply from Marionette:Register
+1613293702712	geckodriver	INFO	Listening on 127.0.0.1:3432
+1613293703263	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofilekzDQJj"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293708224	Marionette	INFO	Listening on port 3441
+1613293708521	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293708544	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293855444	geckodriver	INFO	Listening on 127.0.0.1:3676
+1613293856018	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofileG0zOCJ"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293861655	Marionette	INFO	Listening on port 3688
+1613293861851	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293861875	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293980729	geckodriver	INFO	Listening on 127.0.0.1:3924
+1613293981301	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofiledBgSSx"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613293986206	Marionette	INFO	Listening on port 3933
+1613293986578	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613293986602	Marionette	ERROR	[15] No reply from Marionette:Register
+1613294044871	geckodriver	INFO	Listening on 127.0.0.1:4096
+1613294045444	mozrunner::runner	INFO	Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\SHELLM~1\\AppData\\Local\\Temp\\rust_mozprofile9pmaVN"
+JavaScript error: hvxo0zbh3go.cfg, line 2: ReferenceError: Components is not defined
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
+1613294048471	Marionette	INFO	Listening on port 4103
+1613294048606	Marionette	WARN	TLS certificate errors will be ignored for this session
+1613294048619	Marionette	ERROR	[15] No reply from Marionette:Register
+console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))

+ 0 - 0
loginTools/cookies/gui2.txt → loginTools/gui2.txt


+ 7 - 5
start.py

@@ -23,11 +23,13 @@ def main_reply():
         for cookie_path in cookies:
             login(driver, cookie_path)
             time.sleep(10)
-            reply(driver)
-            time.sleep(10)
-            reply(driver)
-            time.sleep(10)
-            reply(driver)
+            reply(driver,
+                  'https://www.mcbbs.net/forum.php?mod=forumdisplay&fid=52&orderby=heats&filter=dateline&dateline=604800')
+            i = 10
+            while i >= 1:
+                time.sleep(10)
+                reply(driver, 'https://www.mcbbs.net/forum-mod-1.html')
+                i = i - 1
         time.sleep(600)