Anne314159 commited on
Commit
fd154a5
·
verified ·
1 Parent(s): 8fd37ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -0
app.py CHANGED
@@ -12,8 +12,10 @@ def fetch_trending_news(niche):
12
  headers = {
13
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
14
  response = requests.get(url, headers=headers)
 
15
  soup = BeautifulSoup(response.content, "html.parser")
16
  news_items = soup.find_all("div", class_="BNeawe vvjwJb AP7Wnd")
 
17
  trending_news = [item.text for item in news_items[:5]] # Extract the top 5 news items
18
  return trending_news
19
 
@@ -30,6 +32,7 @@ def page_trending_niche():
30
  if st.button('Fetch Trending News'):
31
  st.write(f"Trending news in {niche}:")
32
  trending_news = fetch_trending_news(niche)
 
33
  for idx, news_item in enumerate(trending_news, start=1):
34
  st.write(f"{idx}. {news_item}")
35
 
 
12
  headers = {
13
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
14
  response = requests.get(url, headers=headers)
15
+ print("Response status code:", response.status_code) # Debug print
16
  soup = BeautifulSoup(response.content, "html.parser")
17
  news_items = soup.find_all("div", class_="BNeawe vvjwJb AP7Wnd")
18
+ print("Number of news items found:", len(news_items)) # Debug print
19
  trending_news = [item.text for item in news_items[:5]] # Extract the top 5 news items
20
  return trending_news
21
 
 
32
  if st.button('Fetch Trending News'):
33
  st.write(f"Trending news in {niche}:")
34
  trending_news = fetch_trending_news(niche)
35
+ print("Trending news:", trending_news) # Debug print
36
  for idx, news_item in enumerate(trending_news, start=1):
37
  st.write(f"{idx}. {news_item}")
38