File size: 987 Bytes
b5b9195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()