This project provides a simple API service that uses Selenium and Google Chrome to take screenshots of websites. It's powered by Flask and can be containerized using Docker for ease of deployment.
- β Requirements
- π οΈ Configuration
- π§βπ» Usage
- π API Documentation
- π³ Running with Docker
- π Community
- π License
Python:
- Flask
- Flask_CORS
- Flask-RESTful
- Gunicorn
- Selenium
- URLlib3
- Werkzeug
Other:
- Google Chrome
- ChromeDriver (required for headless operation)
Install the required Python packages with pip:
pip install -r requirements.txt
Note: You will also need ChromeDriver installed for headless operation on servers.
You can configure the API through environment variables such as setting the Flask secret key and the bearer token for authentication. The required environment variables are:
BEARER_TOKEN
: The token for bearer authentication.ALLOWED_ORIGINS
: A comma-separated list of domains that are allowed to make cross-origin requests (CORS) to the API.
To start the Flask development server:
export ALLOWED_ORIGINS=*
python app.py
To run in production:
export BEARER_TOKEN=your_api_authentication_token
export ALLOWED_ORIGINS=https://example.com
python -m gunicorn --config ./gunicorn_config.py app:app
Please refer to our comprehensive API documentation for detailed information about this service, including examples and usage guidelines. The API documentation provides a user-friendly interface for understanding how to use the Screenshot API effectively.
Make a GET request to /screenshot
endpoint with the following parameters:
url
(required): The URL of the website to screenshot.viewport
(optional, default '1440x900'): The viewport size.format
(optional, default 'PNG'): The screenshot format, supports PNG, JPG.delay
(optional, default '0'): The delay before the screenshot is taken to allow the page to load.
Request to capture a screenshot:
GET https://example.com/screenshot?url=https://example.com&viewport=1024x768&format=jpg&delay=1
With cURL on command line:
curl -H "Authorization: Bearer YOUR_API_AUTHENTICATION_TOKEN" \
"https://example.com/screenshot?url=https%3A%2F%2Fexample.com&viewport=1024x768&format=jpg&delay=1" \
--output screenshot.jpg
To build and run the application locally using Docker for testing:
docker buildx build --platform linux/amd64 -t selenium-screenshots .
docker run --platform linux/amd64 -p 5000:8080 \
-e ALLOWED_ORIGINS="*" \
--name screenshot-service \
selenium-screenshots
Or pull the pre-built Docker image from GHCR.io on a server for production:
docker pull ghcr.io/rahb-realtors-association/selenium-screenshots:latest
docker run -d -p 8080:8080 \
-e BEARER_TOKEN="your_api_authentication_token" \
-e ALLOWED_ORIGINS="https://example.com" \
--name screenshot-service \
ghcr.io/rahb-realtors-association/selenium-screenshots:latest
Contributions, bug reports, and feature requests are welcome! Please refer to the contributing guidelines and the code of conduct.
Encountered a bug? Open an issue with details about the bug and how it can be reproduced.
This project is open source under the MIT license. See the LICENSE file for more info. π