nlpblogs commited on
Commit
4ba793c
·
verified ·
1 Parent(s): 065d889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -107,7 +107,7 @@ if st.button("Sentiment Analysis", type="secondary"):
107
  placeholder = st.empty()
108
  progress_bar = st.progress(0)
109
 
110
- for item in range(150):
111
  try:
112
  body = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.TAG_NAME, "body")))
113
  body.send_keys(Keys.END)
@@ -124,15 +124,15 @@ if st.button("Sentiment Analysis", type="secondary"):
124
  data = []
125
  try:
126
  wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#contents #contents")))
127
- comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
128
- comments = driver.find_element(By.CSS_SELECTOR,'div.author-info time')
129
- comments = comments.get_attribute('datetime')
130
  user_id = 1
131
- for comment in comments:
132
-
133
- data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp})
134
  user_id += 1
135
- data = [dict(t) for t in {tuple(d.items()) for d in data}]
 
136
  except Exception as e:
137
  st.error(f"Exception during comment extraction: {e}")
138
  driver.quit()
 
107
  placeholder = st.empty()
108
  progress_bar = st.progress(0)
109
 
110
+ for item in range(30):
111
  try:
112
  body = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.TAG_NAME, "body")))
113
  body.send_keys(Keys.END)
 
124
  data = []
125
  try:
126
  wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#contents #contents")))
127
+ comment_elements = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
128
+ comment_date_element = driver.find_element(By.CSS_SELECTOR,'div.author-info time')
129
+ timestamp = comment_date_element.get_attribute('datetime') # Get timestamp
130
  user_id = 1
131
+ for comment_element in comment_elements: # Iterate through comment elements
132
+ data.append({"User ID": user_id, "Comment": comment_element.text, "comment_date": timestamp})
 
133
  user_id += 1
134
+ data = [dict(t) for t in {tuple(d.items()) for d in data}] # Remove duplicates
135
+
136
  except Exception as e:
137
  st.error(f"Exception during comment extraction: {e}")
138
  driver.quit()