naufalnashif commited on
Commit
02fe0bc
·
1 Parent(s): 045f2fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -11,18 +11,12 @@ def scrape_e_commerce(nama_barang, num_items):
11
  products = []
12
  page = 1
13
  query = quote(nama_barang)
14
- progress_text = "Scraping in progress. Please wait."
15
- my_bar = st.progress(len(products), text=progress_text)
16
 
17
- for percent_complete in range(num_items):
18
- #while len(products) < num_items :
19
- prop = min(len(products) / num_items,1)
20
- my_bar.progress(prop, text=progress_text)
21
 
22
- if len (products) > num_items :
23
- products = products[:num_items]
24
- break
25
-
26
  url = f"https://www.klikindomaret.com/search/?key={query}&categories=&productbrandid=&sortcol=&pagesize=54&page={page}&startprice=&endprice=&attributes=&ShowItem="
27
  response = requests.get(url)
28
  soup = BeautifulSoup(response.text, 'html.parser')
@@ -57,6 +51,13 @@ def scrape_e_commerce(nama_barang, num_items):
57
  'link': product_link
58
  })
59
 
 
 
 
 
 
 
 
60
  page += 1
61
 
62
  time.sleep(1)
 
11
  products = []
12
  page = 1
13
  query = quote(nama_barang)
 
 
14
 
 
 
 
 
15
 
16
+ while len(products) < num_items :
17
+ progress_text = "Scraping in progress. Please wait."
18
+ my_bar = st.progress(len(products), text=progress_text)
19
+
20
  url = f"https://www.klikindomaret.com/search/?key={query}&categories=&productbrandid=&sortcol=&pagesize=54&page={page}&startprice=&endprice=&attributes=&ShowItem="
21
  response = requests.get(url)
22
  soup = BeautifulSoup(response.text, 'html.parser')
 
51
  'link': product_link
52
  })
53
 
54
+ prop = min(len(products) / num_items,1)
55
+ my_bar.progress(prop, text=progress_text)
56
+
57
+ if len (products) > num_items :
58
+ products = products[:num_items]
59
+ break
60
+
61
  page += 1
62
 
63
  time.sleep(1)