diff --git a/serverPython/__pycache__/facebook_bot.cpython-314.pyc b/serverPython/__pycache__/facebook_bot.cpython-314.pyc new file mode 100644 index 0000000..4136a3e Binary files /dev/null and b/serverPython/__pycache__/facebook_bot.cpython-314.pyc differ diff --git a/serverPython/__pycache__/main.cpython-314.pyc b/serverPython/__pycache__/main.cpython-314.pyc index b3c21c3..d4a61f2 100644 Binary files a/serverPython/__pycache__/main.cpython-314.pyc and b/serverPython/__pycache__/main.cpython-314.pyc differ diff --git a/serverPython/facebook_bot.py b/serverPython/facebook_bot.py index 3ffdd05..8777c63 100644 --- a/serverPython/facebook_bot.py +++ b/serverPython/facebook_bot.py @@ -67,30 +67,34 @@ class FacebookBot: c_desc_en = self.d(descriptionMatches="(?i)^comment$") c_text_en = self.d(textMatches="(?i)^comment$") - btn = None - if c_desc_vn.exists: btn = c_desc_vn - elif c_text_vn.exists: btn = c_text_vn - elif c_desc_en.exists: btn = c_desc_en - elif c_text_en.exists: btn = c_text_en + # Lấy tất cả các nút có thể là nút Bình luận + candidates = [] + if c_desc_vn.exists: candidates.extend([c_desc_vn[i] for i in range(c_desc_vn.count)]) + if c_text_vn.exists: candidates.extend([c_text_vn[i] for i in range(c_text_vn.count)]) + if c_desc_en.exists: candidates.extend([c_desc_en[i] for i in range(c_desc_en.count)]) + if c_text_en.exists: candidates.extend([c_text_en[i] for i in range(c_text_en.count)]) - if btn and btn.exists: + # Chỉ lấy những nút nằm dưới khu vực Header của Facebook (Y > 350) + btn = None + for c in candidates: + if c.info["bounds"]["bottom"] > 350: + btn = c + break + + if btn: if current_post_count == post_index: comment_btn = btn break else: - logging.info(f"Đã thấy bài viết thứ {current_post_count}, đang đẩy nó ra khỏi màn hình để tìm bài {post_index}...") - bounds = btn[0].info["bounds"] - start_y = bounds["bottom"] + logging.info(f"Đã thấy bài viết thứ {current_post_count}, đang đẩy nó vào góc khuất để tìm bài {post_index}...") + bounds = btn.info["bounds"] center_x = (bounds["left"] + bounds["right"]) // 2 + start_y = bounds["bottom"] - # Nếu nút đang nằm ở nửa dưới màn hình, vuốt nó lên sát mép trên - if start_y > 300: - self.d.swipe(center_x, start_y, center_x, 250, duration=0.4) - time.sleep(1) - - # Bồi thêm một cú vuốt 400 pixel nữa để tống cổ hoàn toàn cái nút này khỏi viền trên màn hình - self.d.swipe(center_x, 600, center_x, 100, duration=0.3) - time.sleep(2) + # Vuốt đúng khoảng cách để đẩy nút Bình luận hiện tại lên tọa độ Y=200 (Vùng bị bỏ qua) + if start_y > 250: + self.d.swipe(center_x, start_y, center_x, 200, duration=0.4) + time.sleep(2) current_post_count += 1 continue