Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files123456789101112131415161718192021222324252627282930import streamlit as stimport requestsfrom bs4 import BeautifulSoupimport csvimport iost.title("ุฃุฏุงุฉ ุงุณุชุฎุฑุงุฌ ุจูุงูุงุช ุงููุชุจ")url = st.text_input("ุงุฏุฎู ุฑุงุจุท ุตูุญุฉ ุงููุชุงููุฌ", "https://books.toscrape.com")button = st.button("ุงุจุฏุฃ ุงูุณุญุจ")if button:response = requests.get(url)soup = BeautifulSoup(response.text, "html.parser")books = soup.find_all("article", class_="product_pod")data = []for book in books:title = book.h3.a["title"]price = book.find("p", class_="price_color").textdata.append([title, price])st.write(f"ุชู ุฅูุฌุงุฏ {len(data)} ูุชุงุจ")st.table(data)output = io.StringIO()writer = csv.writer(output)writer.writerow(["Title", "Price"])writer.writerows(data)st.download_button("ุชูุฒูู CSV", output.getvalue(), "books.csv", "text/csv")1234567891011121314151617181920212223242526272829303132# โโโ ุงูุชูููุฐ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโif button or auto_refresh > 0:placeholder = st.empty()while True:with placeholder.container():data = scrape_books(url)filtered = filter_sort(data, search_query, max_price, sort_by)st.markdown(f'<span class="count-badge"> ุชู ุฅูุฌุงุฏ {len(filtered)} ูุชุงุจ</span>', unsafe_allow_html=True)st.write("")# ุนุฑุถ ุงููุชุจ ูุจุทุงูุงุชfor book in filtered:st.markdown(f"""<div class="book-card"><b>{book['title']}</b><br>ุงูุณุนุฑ: {book['price_text']}</div>""", unsafe_allow_html=True)# ุชูุฒูู CSVoutput = io.StringIO()writer = csv.writer(output)writer.writerow(["Title", "Price"])writer.writerows([[b["title"], b["price_text"]] for b in filtered])st.download_button(" ุชูุฒูู CSV", output.getvalue(), "books.csv", "text/csv")if auto_refresh == 0:breaktime.sleep(auto_refresh)st.rerun()
src/streamlit_app.py+27-25