From 3e9ea4f148c406cc5ffec59f2eac433c219a5466 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 28 三月 2025 14:20:42 +0800 Subject: [PATCH] 初始化导入 --- comment.py | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-) diff --git a/comment.py b/comment.py index cc8a11c..c0e93a2 100644 --- a/comment.py +++ b/comment.py @@ -9,6 +9,8 @@ from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +import setting + class CommentManager: @@ -29,7 +31,8 @@ comment_template_str = "" # 灏嗕腑鏂囨浛鎹负姝e垯琛ㄨ揪寮忔敮鎸佺殑unicode缂栫爜 comment_template_str = comment_template_str.encode('unicode_escape').decode("utf-8") - self.comment_templates = [(x.split("#")[0], x.split("#")[1]) if x.find("#")>=0 for x in comment_template_str.split("\n")] + self.comment_templates = [(x.split("#")[0], x.split("#")[1]) for x in comment_template_str.split("\n") if + x.find("#") >= 0] self.driver = None def __init(self): @@ -49,7 +52,7 @@ element = wait.until(EC.visibility_of_element_located((By.ID, "side-bar"))) threading.Thread(target=lambda: self.click_like(self.driver), daemon=True).start() - def __process_like(self,comment_content, comment_element): + def __process_like(self, comment_content, comment_element): """ 澶勭悊鍗曟潯璇勮鐨勮禐 :param comment_content: @@ -71,19 +74,22 @@ like.click() self.driver.implicitly_wait(2) - def __process_reply(self, comment_content, comment_element): + def __process_reply(self, comment_content, comment_element): """ 澶勭悊鍗曟潯璇勮鐨勫洖澶� :param comment_content: :param comment_element: :return: """ + def get_reply_comment(nick_name, content): + if not setting.is_reply_comment(): + return None # 鍐呭鏄惁绗﹀悎鏍囧噯 for t in self.comment_templates: if re.match(t[0], content): # 婊¤冻鍐呭 - retrun t[1].replace("[鏄电О]",nick_name) + return t[1].replace("[鏄电О]", nick_name) comment_pattern = re.compile(r'[\u4e00-\u9fa5]+') comment_content = re.sub("<img.*?>", "", comment_content) @@ -99,25 +105,24 @@ print("杩樻病鍥炲銆傘�傘�傘��") comment_actions = comment_element.find_element(By.CLASS_NAME, "action-list").find_elements(By.CLASS_NAME, - "action-item") + "action-item") # 鐐瑰嚮璇勮 comment_actions[1].click() wait = WebDriverWait(self.driver, 5) # 鏈�澶氱瓑寰�10绉� element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "comment-create-content"))) - - replay_content = get_reply_comment(, comment_element) + # TODO 鏄电О + replay_content = get_reply_comment("鏄电О", comment_element) if not replay_content: # 涓嶉渶瑕佽瘎璁� return self.driver.find_element(By.CLASS_NAME, - "comment-create-content").find_element(By.TAG_NAME, - "textarea").send_keys(replay_content) + "comment-create-content").find_element(By.TAG_NAME, + "textarea").send_keys(replay_content) self.driver.implicitly_wait(1) self.driver.find_element(By.CLASS_NAME, - "comment-create-content").find_element(By.XPATH, "div[3]/div[2]").click() + "comment-create-content").find_element(By.XPATH, "div[3]/div[2]").click() time.sleep(2) - def __click_like_all(self, driver, start_index=0): scroll_list = driver.find_element(By.CLASS_NAME, "feed-comment__wrp") @@ -171,7 +176,7 @@ if __name__ == "__main__": # CommentManager().start_process_comment() - s ="浣犲ソ" + s = "浣犲ソ" print(s.encode('unicode_escape').decode("utf-8")) # if __name__ == "__main__": -- Gitblit v1.8.0