Commit
·
d4f441a
1
Parent(s):
515bc7b
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import streamlit as st
|
|
6 |
import json
|
7 |
import time
|
8 |
import logging
|
|
|
9 |
|
10 |
from selenium import webdriver
|
11 |
from selenium.common.exceptions import WebDriverException
|
@@ -70,46 +71,11 @@ def scrape_shopee(nama_barang, num_items):
|
|
70 |
page = 1
|
71 |
query = quote(nama_barang)
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
options.add_argument('--disable-dev-shm-usage')
|
79 |
-
|
80 |
-
driver = webdriver.Chrome(options=options)
|
81 |
-
|
82 |
-
|
83 |
-
try :
|
84 |
-
|
85 |
-
url = f'https://shopee.co.id/search?keyword={query}&page={page}'
|
86 |
-
driver.get(url)
|
87 |
-
|
88 |
-
html = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML")
|
89 |
-
st.write(html)
|
90 |
-
soup = BeautifulSoup(html, "html.parser")
|
91 |
-
|
92 |
-
for i in soup.find_all('div', class_ = "ie3A+n bM+7UW Cve6sh" ):
|
93 |
-
products.append(i.text)
|
94 |
-
|
95 |
-
except requests.exceptions.RequestException as e:
|
96 |
-
logging.error(f"Terjadi kesalahan saat mengirim permintaan: {e}")
|
97 |
-
st.error(f"Terjadi kesalahan saat mengirim permintaan: {e}")
|
98 |
-
|
99 |
-
except requests.exceptions.HTTPError as e:
|
100 |
-
logging.error(f"HTTP Error: {e}")
|
101 |
-
st.error(f"HTTP Error: {e}")
|
102 |
-
|
103 |
-
except Exception as e:
|
104 |
-
logging.error(f"Terjadi kesalahan yang tidak diketahui: {e}")
|
105 |
-
st.error(f"Terjadi kesalahan yang tidak diketahui: {e}")
|
106 |
-
|
107 |
-
except WebDriverException as e:
|
108 |
-
st.error(f"An error occurred: {e}")
|
109 |
-
finally:
|
110 |
-
if driver:
|
111 |
-
driver.quit()
|
112 |
-
|
113 |
return products
|
114 |
|
115 |
@st.cache_data
|
|
|
6 |
import json
|
7 |
import time
|
8 |
import logging
|
9 |
+
from requests_html import HTMLSession
|
10 |
|
11 |
from selenium import webdriver
|
12 |
from selenium.common.exceptions import WebDriverException
|
|
|
71 |
page = 1
|
72 |
query = quote(nama_barang)
|
73 |
|
74 |
+
url = f'https://shopee.co.id/search?keyword={query}&page={page}'
|
75 |
+
session = HTMLSession()
|
76 |
+
response = session.get(url)
|
77 |
+
response.html.render()
|
78 |
+
st.write(response.html.html)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
return products
|
80 |
|
81 |
@st.cache_data
|