Skip to content

Commit

Permalink
facebook: add conditional check if text exists
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Oct 13, 2024
1 parent 6ab58c8 commit 7f4fad4
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions automon/integrations/facebook/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def content_unavailable(self):

try:
text = self._browser.wait_for_xpath(self._xpath_content_unavailable, timeout=5)
text = text.text
if text:
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand All @@ -66,9 +67,10 @@ def creation_date(self):
value='span',
by=self._browser.by.TAG_NAME
)
text = text[0]
text = text.text.split('See more')[0]
text = text.strip()
if text:
text = text[0]
text = text.text.split('See more')[0]
text = text.strip()
logger.debug(text)
return text
except Exception as error:
Expand Down Expand Up @@ -115,11 +117,12 @@ def history(self):
value='span',
by=self._browser.by.TAG_NAME
)
text = text[-1]
text = text.text
if 'See more' in text:
text = text.split('See more')
text = text[0]
if text:
text = text[-1]
text = text.text
if 'See more' in text:
text = text.split('See more')
text = text[0]
logger.debug(text)
return text
except Exception as error:
Expand All @@ -129,7 +132,8 @@ def history(self):
def temporarily_blocked(self):
try:
text = self._browser.wait_for_xpath(self._xpath_temporarily_blocked, timeout=5)
text = text.text
if text:
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand All @@ -145,8 +149,9 @@ def members(self):
value='span',
by=self._browser.by.TAG_NAME
)
text = text[-1]
text = text.text
if text:
text = text[-1]
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand All @@ -167,7 +172,8 @@ def members_count(self):
def must_login(self):
try:
text = self._browser.wait_for_anything(self._xpath_must_login)
text = text.text
if text:
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand All @@ -182,8 +188,9 @@ def posts_monthly(self):
value='span',
by=self._browser.by.TAG_NAME
)
text = text[-1]
text = text.text
if text:
text = text[-1]
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand All @@ -209,8 +216,9 @@ def posts_today(self):
value='span',
by=self._browser.by.TAG_NAME
)
text = text[-1]
text = text.text
if text:
text = text[-1]
text = text.text
logger.debug(text)
return text
except Exception as error:
Expand Down Expand Up @@ -246,12 +254,10 @@ def privacy(self):
return_first=True,
)
if text:
break

text = text[-1]
text = text.text
logger.debug(text)
return text
text = text[-1]
text = text.text
logger.debug(text)
return text
except Exception as error:
message, session, stacktrace = self.error_parsing(error)
logger.error(f'{self.url} :: {message=} :: {session=} :: {stacktrace=}')
Expand All @@ -272,12 +278,10 @@ def privacy_details(self):
exact_match=True
)
if text:
break

text = text[0]
text = text.text
logger.debug(text)
return text
text = text[0]
text = text.text
logger.debug(text)
return text
except Exception as error:
message, session, stacktrace = self.error_parsing(error)
logger.error(f'{self.url} :: {message=} :: {session=} :: {stacktrace=}')
Expand All @@ -291,9 +295,10 @@ def title(self) -> str:
logger.error(text)
return ''

text = text.split('|')
text = text[0]
text = text.strip()
if text:
text = text.split('|')
text = text[0]
text = text.strip()
logger.debug(text)
return text
except Exception as error:
Expand Down Expand Up @@ -328,12 +333,10 @@ def visible(self) -> str:
exact_match=True
)
if text:
break

text = text[-1]
text = text.text
logger.debug(text)
return text
text = text[-1]
text = text.text
logger.debug(text)
return text
except Exception as error:
message, session, stacktrace = self.error_parsing(error)
logger.error(f'{self.url} :: {message=} :: {session=} :: {stacktrace=}')
Expand Down

0 comments on commit 7f4fad4

Please sign in to comment.