A Python-based scraper for collecting product information from Shopee Thailand.
This project automates the following steps:
- Login with your Shopee credentials
- Search for a specific keyword
- Extract product details (name, price, variants, stock, category, seller info, ratings, etc.)
- Logout to end the session cleanly
Organized into classes such as:
LoginHandlerSearchHandlerProductScraperVariantScraper
All are orchestrated by a ShopeeScraper facade.
AbstractScraperdefines a template method (scrape()) withbefore_scrape(),do_scrape(), andafter_scrape().ShopeeScraperprovides a unified interface (facade) to simplify the scraping workflow.
Utilizes SeleniumBase under the hood for browser automation, including support for undetected drivers and extra convenience methods.
- Handlers for login, search, product details, and variant selection reside in
handlers/folder. - Utilities such as scrolling and parsing are in
utils.py. - Data models like
ProductData(andScrapeParamsfor parameter validation) are defined inmodels.py.
main.py: Entry point that initializes and runs the scraper.abstract_scraper.py: Defines theAbstractScraperbase class with a template method.shopee_scraper.py: The mainShopeeScraperfacade that orchestrates the scraping process.
-
login_handler.py: Handles the login flow. -
search_handler.py: Handles keyword search. -
product_scraper.py: Extracts product info (price, description, rating, etc.). -
variant_scraper.py: Extracts variant options (e.g., sizes, colors) and stock per variant. -
models.py: Contains data model classes (ProductData) and a Pydantic model (ScrapeParams) for validating parameters. -
utils.py: Contains common utility functions (scrolling, parsing, etc.).
git clone https://github.com/toptankcpe/shopee-scraper.git
cd shopee-scraperpip install -r requirements.txtEnsure you have Python 3.7+ and a supported WebDriver environment.
This project accepts parameters via the command-line.
--username: Your Shopee username.--password: Your Shopee password.--keyword: The search keyword.
--numpage: The number of pages to scrape.--itemperpage: The number of items per page to scrape.
python main.py --username your_username --password your_password --keyword "iphone" --numpage 2 --itemperpage 5A browser window should open, navigate to Shopee, log in with your credentials, perform the search, scrape the product data, and then log out.
By default, the scraper prints the resulting JSON output to the console in the after_scrape() method. You can modify shopee_scraper.py or main.py if you wish to store the output in a file or database.
Shopee may occasionally require manual CAPTCHA solving. When this occurs, you may need to solve it for the scraper to continue.
Use the scraper responsibly to avoid IP blocking or violations of Shopee's terms of service.
This project is for educational purposes. Please ensure compliance with Shopee's policies before scraping.
Contributions are welcome! Feel free to submit issues for bugs or suggestions, or open a pull request with improvements. Please follow existing coding styles and add tests where appropriate.
This project is released under the MIT License. You can freely use or modify this software under the terms of the license.