Update app.py
Browse files
app.py
CHANGED
@@ -70,23 +70,15 @@ if st.button("Sentiment Analysis", type="secondary"):
|
|
70 |
for comment in comments:
|
71 |
timestamp = None
|
72 |
try:
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
timestamp_element = comment.find_element(By.XPATH, './ancestor::ytd-comment-renderer//yt-formatted-string[contains(@class, "time-text")]')
|
80 |
-
timestamp = timestamp_element.text
|
81 |
-
except Exception:
|
82 |
-
try:
|
83 |
-
#try grabbing the a tag.
|
84 |
-
timestamp_element = comment.find_element(By.XPATH, './ancestor::ytd-comment-renderer//a[@id="time"]')
|
85 |
-
timestamp = timestamp_element.text
|
86 |
-
except Exception as inner_e:
|
87 |
-
print(f"Timestamp not found for comment: {comment.text}. Error: {inner_e}") #debug
|
88 |
data.append({"Comment": comment.text, "comment_date": timestamp})
|
89 |
|
|
|
90 |
except Exception as e:
|
91 |
st.error(f"Exception during comment extraction: {e}")
|
92 |
driver.quit()
|
|
|
70 |
for comment in comments:
|
71 |
timestamp = None
|
72 |
try:
|
73 |
+
comment_text = comment.text
|
74 |
+
date_match = re.search(r'\d+ (day|week|month|year)s? ago', comment_text) #Example regex.
|
75 |
+
if date_match:
|
76 |
+
timestamp = date_match.group(0)
|
77 |
+
except Exception as e:
|
78 |
+
st.error(f"Error extracting date with regex: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
data.append({"Comment": comment.text, "comment_date": timestamp})
|
80 |
|
81 |
+
|
82 |
except Exception as e:
|
83 |
st.error(f"Exception during comment extraction: {e}")
|
84 |
driver.quit()
|