diff --git a/automon/integrations/facebook/groups.py b/automon/integrations/facebook/groups.py index 225589aa..9f5269c3 100644 --- a/automon/integrations/facebook/groups.py +++ b/automon/integrations/facebook/groups.py @@ -15,18 +15,12 @@ class FacebookGroups(object): _xpath_content_unavailable = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[1]/div[2]/div[1]/span' - _xpath_history = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div/div[1]/div[1]/div[4]/div/div/div/div/div/div[1]/div/div/div/div/div/div[2]/div[4]/div/div/div[2]/div/div[2]/span/span' - _xpath_title = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div[2]/div/div/div/div/div[1]/div/div/div/div/div/div[1]/h1/span/a' _xpath_temporarily_blocked = '/html/body/div[1]/div[2]/div[1]/div/div/div[1]/div/div[2]' _xpath_must_login = '/html/body/div[1]/div[1]/div[1]/div/div[2]/div/div' - _xpath_privacy = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[4]/div/div/div/div/div/div[1]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div/div[1]/span/span' - - _xpath_privacy_details = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[4]/div/div/div/div/div/div[1]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div/div[2]/span/span' - _xpath_visible = '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[4]/div/div/div/div/div/div[1]/div/div/div/div/div/div[2]/div[3]/div/div/div[2]/div/div[2]/span/span' RATE_PER_MINUTE = 2 @@ -56,7 +50,7 @@ def content_unavailable(self): """This content isn't available right now""" try: - text = self._browser.wait_for_anything(self._xpath_content_unavailable) + text = self._browser.wait_for_xpath(self._xpath_content_unavailable, timeout=5) text = text.text logger.debug(text) return text @@ -113,8 +107,16 @@ def average_rate(self): def history(self): try: - text = self._browser.wait_for_anything(self._xpath_history) + text = self._browser.wait_for_anything( + match='Group created', + value='span', + by=self._browser.by.TAG_NAME + ) + text = text[-1] text = text.text + if 'See more' in text: + text = text.text.split('See more') + text = text[0] logger.debug(text) return text except Exception as error: @@ -124,7 +126,7 @@ def history(self): def temporarily_blocked(self): try: - text = self._browser.wait_for_xpath(self._xpath_temporarily_blocked) + text = self._browser.wait_for_xpath(self._xpath_temporarily_blocked, timeout=5) text = text.text logger.debug(text) return text @@ -230,7 +232,24 @@ def posts_today_count(self): def privacy(self): try: - text = self._browser.wait_for_anything(self._xpath_privacy) + knwon_privacy = [ + 'Public', + 'Private', + 'Visible', + ] + + for privacy in knwon_privacy: + text = self._browser.wait_for_anything( + match=privacy, + value='span', + by=self._browser.by.TAG_NAME, + exact_match=True, + return_first=True, + ) + if text: + break + + text = text[-1] text = text.text logger.debug(text) return text @@ -242,7 +261,9 @@ def privacy(self): def privacy_details(self): try: - text = self._browser.wait_for_anything(self._xpath_privacy_details) + text = self._browser.wait_for_anything( + match='' + ) text = text.text logger.debug(text) return text