Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
from bs4 import BeautifulSoup | |
import pandas as pd | |
# Function to fetch and parse the HTML content | |
def fetch_product_info(url): | |
response = requests.get(url) | |
response.encoding = 'utf-8' # Ensure correct encoding | |
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 app | |
def main(): | |
st.title("Product Information Scraper") | |
url = 'https://eshop.ttl.com.tw/b2b_cpinfo.aspx?id=11530&catid=24' | |
st.write(f"Fetching data from: {url}") | |
try: | |
title, price = fetch_product_info(url) | |
data = {'Title': [title], 'Price': [price]} | |
df = pd.DataFrame(data) | |
st.write("Product Information:") | |
st.dataframe(df) | |
except Exception as e: | |
st.error(f"Error fetching data: {e}") | |
if __name__ == "__main__": | |
main() | |