Commit
·
0e2310d
1
Parent(s):
9208784
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,7 @@ def scrape_e_commerce(nama_barang, num_items):
|
|
11 |
products = []
|
12 |
page = 1
|
13 |
query = quote(nama_barang)
|
14 |
-
|
15 |
-
my_bar = st.progress(len(products), text=progress_text)
|
16 |
|
17 |
for percent_complete in range(num_items):
|
18 |
|
@@ -23,6 +22,9 @@ def scrape_e_commerce(nama_barang, num_items):
|
|
23 |
product_list = soup.find_all('a', href=True)
|
24 |
|
25 |
for product in product_list:
|
|
|
|
|
|
|
26 |
product_href = product['href']
|
27 |
if '/product/' in product_href:
|
28 |
product_name = product.find('div', class_='title').text.strip()
|
@@ -48,13 +50,13 @@ def scrape_e_commerce(nama_barang, num_items):
|
|
48 |
'discount_percentage': discount_percentage,
|
49 |
'link': product_link
|
50 |
})
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
my_bar.progress(prop, text=progress_text)
|
55 |
-
break
|
56 |
-
prop = len(products) / num_items
|
57 |
my_bar.progress(prop, text=progress_text)
|
|
|
|
|
|
|
58 |
|
59 |
page += 1
|
60 |
|
@@ -69,7 +71,7 @@ st.title("Scraping E-Commerce")
|
|
69 |
|
70 |
with st.expander("Settings :"):
|
71 |
# Pilihan untuk memilih situs web
|
72 |
-
selected_site = st.selectbox("Pilih Situs Web :", ["klikindomaret.com", "
|
73 |
|
74 |
nama_barang = st.text_input("Masukkan Nama Barang :")
|
75 |
num_items = st.number_input("Masukkan Estimasi Banyak Data :", min_value = 1, step = 1, placeholder="Type a number...")
|
@@ -123,6 +125,9 @@ if scraping_done:
|
|
123 |
elif download_format == "JSON":
|
124 |
json_data = pd.DataFrame(scraped_products).to_json(orient="records")
|
125 |
st.download_button(label=f"Unduh JSON ({len(hidden_data)} data)", data=json_data, key="json_download", file_name=output_file_json)
|
|
|
|
|
|
|
126 |
if not scraping_done:
|
127 |
st.write("Tidak ada data untuk diunduh.")
|
128 |
|
|
|
11 |
products = []
|
12 |
page = 1
|
13 |
query = quote(nama_barang)
|
14 |
+
|
|
|
15 |
|
16 |
for percent_complete in range(num_items):
|
17 |
|
|
|
22 |
product_list = soup.find_all('a', href=True)
|
23 |
|
24 |
for product in product_list:
|
25 |
+
progress_text = "Scraping in progress. Please wait."
|
26 |
+
my_bar = st.progress(len(products), text=progress_text)
|
27 |
+
|
28 |
product_href = product['href']
|
29 |
if '/product/' in product_href:
|
30 |
product_name = product.find('div', class_='title').text.strip()
|
|
|
50 |
'discount_percentage': discount_percentage,
|
51 |
'link': product_link
|
52 |
})
|
53 |
+
if len (products) > num_items :
|
54 |
+
products = products[:num_items]
|
55 |
+
prop = min(len(products) / num_items, 1)
|
|
|
|
|
|
|
56 |
my_bar.progress(prop, text=progress_text)
|
57 |
+
break
|
58 |
+
prop = min(len(products) / num_items,1)
|
59 |
+
my_bar.progress(prop, text=progress_text)
|
60 |
|
61 |
page += 1
|
62 |
|
|
|
71 |
|
72 |
with st.expander("Settings :"):
|
73 |
# Pilihan untuk memilih situs web
|
74 |
+
selected_site = st.selectbox("Pilih Situs Web :", ["klikindomaret.com", "shopee.co.id(under maintenance)"])
|
75 |
|
76 |
nama_barang = st.text_input("Masukkan Nama Barang :")
|
77 |
num_items = st.number_input("Masukkan Estimasi Banyak Data :", min_value = 1, step = 1, placeholder="Type a number...")
|
|
|
125 |
elif download_format == "JSON":
|
126 |
json_data = pd.DataFrame(scraped_products).to_json(orient="records")
|
127 |
st.download_button(label=f"Unduh JSON ({len(hidden_data)} data)", data=json_data, key="json_download", file_name=output_file_json)
|
128 |
+
elif not hidden_data:
|
129 |
+
st.warning(f"Tidak ada data pada query '{query}'", icon="⚠️")
|
130 |
+
|
131 |
if not scraping_done:
|
132 |
st.write("Tidak ada data untuk diunduh.")
|
133 |
|