A web scraping service built with Node.js, Express, and Puppeteer that allows you to extract HTML content from web pages using CSS selectors.
- Web scraping API endpoint
- CSS selector-based content extraction
- Built with TypeScript
- Containerized with Docker
- Development hot reload
Scrapes content from a webpage using a CSS selector.
Query Parameters:
url(required): The URL of the webpage to scrapeselector(required): CSS selector for the element to extract
Example:
GET /handle?url=https://example.com&selector=.main-content
Response:
{
"html": "<div class=\"main-content\">...</div>"
}- Node.js 18+ (for local development)
- Docker and Docker Compose (for containerized development)
Docker is the recommended approach as it handles all Puppeteer dependencies automatically and provides a consistent environment.
-
Clone the repository
git clone https://github.com/wellsm/scrapper.git cd scrapper -
Create the external network (if it doesn't exist)
docker network create kwai
-
Start the application
docker-compose up --build
-
Access the application
- The server will be available at:
http://localhost:7060 - Test the scraping endpoint:
http://localhost:7060/handle?url=https://www.scrapethissite.com/pages/&selector=.page-title
- The server will be available at:
The Docker setup includes:
- Automatic dependency installation
- TypeScript compilation
- All Puppeteer dependencies pre-installed
- No manual system dependency management required
-
Clone the repository
git clone https://github.com/wellsm/scrapper.git cd scrapper -
Install dependencies
npm install
-
Development mode (with hot reload)
npm run dev
-
Production build and start
npm run build npm start
-
Access the application
- The server will be available at:
http://localhost:3000 - Test the scraping endpoint:
http://localhost:7060/handle?url=https://www.scrapethissite.com/pages/&selector=.page-title
- The server will be available at:
Note: Local development requires installing Puppeteer system dependencies, which can be complex. Consider using Docker for easier setup. Refer to the Puppeteer documentation for system-specific requirements.
npm run dev- Start development server with hot reloadnpm run build- Compile TypeScript to JavaScriptnpm start- Start production server
scrapper/
├── src/
│ └── index.ts # Main application entry point
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build configuration
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
The application uses the following configuration:
- Port: 3000 (local), 7060 (Docker external)
- Timezone: America/Sao_Paulo
- Node.js version: 22 (in Docker)
-
Port already in use
- For Docker: Change the external port in
docker-compose.ymlif 7060 is occupied - For local development: The default port 3000 can be modified in
src/index.ts - Check if another application is using the port:
lsof -i :3000orlsof -i :7060
- For Docker: Change the external port in
-
Puppeteer issues (Local Development)
- Recommended: Use Docker to avoid Puppeteer setup complexity
- For local setup, ensure all system dependencies are installed:
- On Linux:
sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo-gobject2 libdrm2 libgtk-3-0 libnspr4 libnss3 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 - On macOS: Usually works out of the box
- On Windows: May require additional setup, Docker recommended
- On Linux:
-
Docker issues
- Ensure the
kwainetwork exists:docker network create kwai - Check if other containers are using the same network
- If build fails, try:
docker-compose down && docker-compose up --build
- Ensure the
-
TypeScript compilation errors
- Run
npm run buildto check for compilation issues - Ensure TypeScript version compatibility
- Run
To view application logs:
# Docker
docker-compose logs -f
# Local development
# Logs will appear in the terminal where you ran npm run dev