Spaces:
Running
Running
gunship999
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,9 @@ def scrape_ranking_news():
|
|
37 |
title = article.find("strong", class_="list_title").text
|
38 |
published_time = article.find("span", class_="list_time").text
|
39 |
link = article.find("a")['href']
|
40 |
-
image
|
|
|
|
|
41 |
|
42 |
news_list.append({
|
43 |
"rank": rank,
|
@@ -64,7 +66,8 @@ if st.button("Start News Scraping"):
|
|
64 |
|
65 |
for index, news in enumerate(news_data):
|
66 |
with cols[col_count]:
|
67 |
-
|
|
|
68 |
st.write(f"**Rank {news['rank']} - {news['publisher']}**")
|
69 |
st.write(f"[{news['title']}]({news['link']})")
|
70 |
st.write(f"🕒 Posted: {news['time']}")
|
|
|
37 |
title = article.find("strong", class_="list_title").text
|
38 |
published_time = article.find("span", class_="list_time").text
|
39 |
link = article.find("a")['href']
|
40 |
+
# Handle cases where image might not exist
|
41 |
+
img_tag = article.find("img")
|
42 |
+
image = img_tag['src'] if img_tag else None
|
43 |
|
44 |
news_list.append({
|
45 |
"rank": rank,
|
|
|
66 |
|
67 |
for index, news in enumerate(news_data):
|
68 |
with cols[col_count]:
|
69 |
+
if news['image']: # Only display image if it exists
|
70 |
+
st.image(news['image'])
|
71 |
st.write(f"**Rank {news['rank']} - {news['publisher']}**")
|
72 |
st.write(f"[{news['title']}]({news['link']})")
|
73 |
st.write(f"🕒 Posted: {news['time']}")
|