nlpblogs commited on
Commit
4bdfac8
·
verified ·
1 Parent(s): 75b7658

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -127,15 +127,14 @@ if st.button("Sentiment Analysis", type="secondary"):
127
  comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
128
  user_id = 1
129
  for comment in comments:
130
-
131
-
132
- timestamp=comments.find_elements(By.CSS_SELECTOR,'//*[contains(@class,"yt-simple-endpoint style-scope yt-formatted-string")]')
133
-
134
- data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp})
135
-
136
-
137
- user_id += 1
138
- data = [dict(t) for t in {tuple(d.items()) for d in data}]
139
  except Exception as e:
140
  st.error(f"Exception during comment extraction: {e}")
141
  driver.quit()
 
127
  comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
128
  user_id = 1
129
  for comment in comments:
130
+ timestamp_elements = comment.find_elements(By.XPATH, './/a[@id="time"]') #Correct XPATH syntax.
131
+ timestamp = "Timestamp not found"
132
+ if timestamp_elements:
133
+ timestamp = timestamp_elements[0].text
134
+ data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp}
135
+ user_id += 1
136
+ data = [dict(t) for t in {tuple(d.items()) for d in data}]
137
+
 
138
  except Exception as e:
139
  st.error(f"Exception during comment extraction: {e}")
140
  driver.quit()