File size: 1,600 Bytes
df1d711 f5f73e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # streamlit_app.py
import os, tempfile, pandas as pd, streamlit as st
from scraper import scrape_tender_list
# must be set before Streamlit initialises metrics
os.environ["STREAMLIT_BROWSER_GATHERUSAGESTATS"] = "false"
st.set_page_config(page_title="TenderDetail Scraper", layout="wide")
st.title("📝 TenderDetail List‑Page Scraper")
with st.expander("ℹ️ Instructions", expanded=True):
st.markdown(
"""
1. Copy any Tenderdetail **list page URL**
(e.g. <https://www.tenderdetail.com/Indian-tender/uadd-tenders>).
2. Paste it below and click **Scrape**.
3. Preview the table, then download it as Excel.
"""
)
url = st.text_input("Tenderdetail list URL", value="https://www.tenderdetail.com/Indian-tender/uadd-tenders")
if st.button("🔍 Scrape"):
if not url.strip():
st.error("Please enter a valid URL.")
st.stop()
with st.spinner("Fetching & parsing…"):
try:
df = scrape_tender_list(url)
except Exception as e:
st.error(f"Scrape failed: {e}")
st.stop()
st.success(f"Found **{len(df)}** tenders.")
st.dataframe(df, use_container_width=True)
# ---- Download as Excel
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
df.to_excel(tmp.name, index=False)
with open(tmp.name, "rb") as f:
st.download_button(
"⬇️ Download Excel",
f,
file_name="tender_list.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
|