diff --git a/serverPython/__pycache__/main.cpython-314.pyc b/serverPython/__pycache__/main.cpython-314.pyc new file mode 100644 index 0000000..b3c21c3 Binary files /dev/null and b/serverPython/__pycache__/main.cpython-314.pyc differ diff --git a/serverPython/facebook_bot.py b/serverPython/facebook_bot.py index 596ac04..161232b 100644 --- a/serverPython/facebook_bot.py +++ b/serverPython/facebook_bot.py @@ -39,14 +39,27 @@ class FacebookBot: self.d.shell(f'am start -a android.intent.action.VIEW -d "fb://group/{group_id}"') time.sleep(8) # Đợi load giao diện group - # Tìm nút "Bình luận" của bài viết đầu tiên hiển thị + # Quét nút Bình luận, nếu không thấy thì vuốt xuống (vì ảnh bìa group che mất) logging.info("Tìm nút Bình luận của bài viết đầu tiên...") - # Facebook dùng description hoặc text, thường là "Bình luận" hoặc "Comment" - comment_btn = self.d(descriptionContains="Bình luận") - if not comment_btn.exists: - comment_btn = self.d(descriptionContains="Comment") + comment_btn = None + + for _ in range(7): # Thử vuốt tối đa 7 lần + # Thử quét bằng Regex (Không phân biệt hoa thường) ở cả description và text + c_desc_vn = self.d(descriptionMatches="(?i).*bình luận.*") + c_text_vn = self.d(textMatches="(?i).*bình luận.*") + c_desc_en = self.d(descriptionMatches="(?i).*comment.*") + c_text_en = self.d(textMatches="(?i).*comment.*") - if comment_btn.exists: + if c_desc_vn.exists: comment_btn = c_desc_vn; break + if c_text_vn.exists: comment_btn = c_text_vn; break + if c_desc_en.exists: comment_btn = c_desc_en; break + if c_text_en.exists: comment_btn = c_text_en; break + + # Vuốt lên một chút + self.d.swipe_ext("up", scale=0.5) + time.sleep(1.5) + + if comment_btn and comment_btn.exists: comment_btn[0].click() # Click vào bài đầu tiên tìm thấy else: self.dump_ui_for_debug("error_fb_no_comment_btn.xml")