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:
self.card = card
self.user = card.find_element(
"xpath", './/div[@data-testid="User-Name"]//span'
).text
try:
self.user = card.find_element(
"xpath", './/div[@data-testid="User-Name"]//span'
).text
except NoSuchElementException:
return
try:
self.handle = card.find_element(

View File

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