Roberta2024 commited on
Commit
b5b9195
·
verified ·
1 Parent(s): 4692302

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ import pandas as pd
5
+
6
+ # Function to fetch and parse the HTML content
7
+ def fetch_product_info(url):
8
+ response = requests.get(url)
9
+ response.encoding = 'utf-8' # Ensure correct encoding
10
+ soup = BeautifulSoup(response.text, 'html.parser')
11
+ title = soup.find('span', id='packagename').text
12
+ price = soup.find('span', id='price1', class_='price product-priceshow').text
13
+ return title, price
14
+
15
+ # Streamlit app
16
+ def main():
17
+ st.title("Product Information Scraper")
18
+
19
+ url = 'https://eshop.ttl.com.tw/b2b_cpinfo.aspx?id=11530&catid=24'
20
+ st.write(f"Fetching data from: {url}")
21
+
22
+ try:
23
+ title, price = fetch_product_info(url)
24
+ data = {'Title': [title], 'Price': [price]}
25
+ df = pd.DataFrame(data)
26
+ st.write("Product Information:")
27
+ st.dataframe(df)
28
+ except Exception as e:
29
+ st.error(f"Error fetching data: {e}")
30
+
31
+ if __name__ == "__main__":
32
+ main()