Back to Home
Shopee.py
INSTALL BASH:

pip install selenium webdriver-manager beautifulsoup4

SCRAPE:

def scrape_shopee_barang(keyword="powerbank"):
    from selenium.webdriver.common.keys import Keys

    options = webdriver.ChromeOptions()
    options.add_argument("--headless")
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

    driver.get("https://shopee.co.id/")
    time.sleep(5)

    # Cari kotak pencarian
    search_box = driver.find_element(By.CLASS_NAME, "shopee-searchbar-input__input")
    search_box.send_keys(keyword)
    search_box.send_keys(Keys.ENTER)

    time.sleep(5)

    soup = BeautifulSoup(driver.page_source, "html.parser")
    produk = soup.select("div.shopee-search-item-result__item")

    hasil = []
    for item in produk[:5]:
        nama = item.select_one("div._10Wbs-")
        harga = item.select_one("span._341bF0")

        if nama and harga:
            hasil.append({
                "nama": nama.get_text(strip=True),
                "harga": harga.get_text(strip=True)
            })

    driver.quit()
    return hasil