nlpblogs commited on
Commit
0b66ee9
·
verified ·
1 Parent(s): 5a1ddac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
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
- # Try a more direct XPath
74
- timestamp_element = comment.find_element(By.XPATH, './ancestor::ytd-comment-renderer//yt-formatted-string[@class="published-time-text style-scope ytd-comment-renderer"]')
75
- timestamp = timestamp_element.text
76
- except Exception:
77
- try:
78
- # Try a more general XPath
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()