Update app.py
Browse files
app.py
CHANGED
@@ -121,20 +121,23 @@ if st.button("Sentiment Analysis", type="secondary"):
|
|
121 |
placeholder.text("Scrolling complete.")
|
122 |
progress_bar.empty()
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
138 |
driver.quit()
|
139 |
df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
|
140 |
st.dataframe(df)
|
|
|
121 |
placeholder.text("Scrolling complete.")
|
122 |
progress_bar.empty()
|
123 |
|
124 |
+
try:
|
125 |
+
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#contents #contents")))
|
126 |
+
comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
|
127 |
+
user_id = 1
|
128 |
+
for comment in comments:
|
129 |
+
timestamp = None
|
130 |
+
try:
|
131 |
+
timestamp_element = comment.find_element(By.XPATH, './ancestor::ytd-comment-renderer//yt-formatted-string[@class="published-time-text style-scope ytd-comment-renderer"]')
|
132 |
+
timestamp = timestamp_element.text
|
133 |
+
except Exception as e:
|
134 |
+
print(f"Timestamp not found for comment: {comment.text}. Error: {e}")
|
135 |
+
data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp})
|
136 |
+
user_id += 1
|
137 |
+
data = [dict(t) for t in {tuple(d.items()) for d in data}]
|
138 |
+
except Exception as e:
|
139 |
+
st.error(f"Exception during comment extraction: {e}")
|
140 |
+
|
141 |
driver.quit()
|
142 |
df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
|
143 |
st.dataframe(df)
|