JERNGOC's picture
Create app.py
fdc5ae8 verified
import streamlit as st
import requests
from bs4 import BeautifulSoup
import pandas as pd
# Function to fetch product details
def fetch_product_details(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
title = soup.find("span", id="packagename").text
price = soup.find("span", id="price1", class_="price product-priceshow").text
return title, price
# Streamlit UI
st.title("Product Details Fetcher")
# Input field for the URL
url = st.text_input("Enter the product URL:", "https://eshop.ttl.com.tw/b2b_cpinfo.aspx?id=5180&catid=6#")
if st.button("Fetch Details"):
if url:
try:
title, price = fetch_product_details(url)
data = {
"標題": [title],
"價格": [price]
}
df = pd.DataFrame(data)
st.write(df)
except Exception as e:
st.error(f"Error fetching details: {e}")
else:
st.warning("Please enter a valid URL.")