add: handle errors for no user element

This commit is contained in:
Jarrian
2023-09-09 17:43:07 +08:00
parent efb0c65c39
commit 07ece4e29a
2 changed files with 9 additions and 3 deletions

View File

@@ -6,9 +6,12 @@ class Tweet:
def __init__(self, card: Chrome) -> None: def __init__(self, card: Chrome) -> None:
self.card = card self.card = card
self.user = card.find_element( try:
"xpath", './/div[@data-testid="User-Name"]//span' self.user = card.find_element(
).text "xpath", './/div[@data-testid="User-Name"]//span'
).text
except NoSuchElementException:
return
try: try:
self.handle = card.find_element( self.handle = card.find_element(

View File

@@ -239,6 +239,9 @@ It may be due to the following:
except StaleElementReferenceException: except StaleElementReferenceException:
callback() callback()
sleep(2) sleep(2)
except Exception as e:
print(f"Error scraping tweets: {e}")
break
print("\n") print("\n")