https://github.com/scrapesome/scrapesome
A Powerful Web Scraper with dynamic rendering support.
https://github.com/scrapesome/scrapesome
asyncio markdown parser playwright python scraper scraping
Last synced: about 1 year ago
JSON representation
A Powerful Web Scraper with dynamic rendering support.
- Host: GitHub
- URL: https://github.com/scrapesome/scrapesome
- Owner: scrapesome
- License: mit
- Created: 2025-05-24T10:03:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-08T04:05:17.000Z (about 1 year ago)
- Last Synced: 2025-06-08T05:39:04.109Z (about 1 year ago)
- Topics: asyncio, markdown, parser, playwright, python, scraper, scraping
- Language: Python
- Homepage: http://scrapesome.github.io/scrapesome/
- Size: 174 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# ScrapeSome










**ScrapeSome** is a lightweight, flexible web scraping library with both **synchronous** and **asynchronous** support. It includes intelligent fallbacks, JavaScript page rendering, response formatting (HTML β Text/JSON/Markdown), and retry mechanisms. Ideal for developers who need robust scraping utilities with minimal setup.
---
## Table of Contents
- [π‘ Why Use ScrapeSome?](#-why-use-scrapesome)
- [π Features](#-features)
- [β Comparison with Alternatives](#-comparison-with-alternatives)
- [π¦ Installation](#-installation)
- [Playwright Setup](#playwright-setup)
- [Windows](#windows)
- [Linux (Ubuntu/Debian)](#linux-ubuntudebian)
- [macOS](#macos)
- [β‘ Quick Start](#-quick-start)
- [π₯οΈ CLI Usage](#-cli-usage)
- [π§° Advanced Usage](#-advanced-usage)
- [π§ͺ Testing](#-testing)
- [βοΈ Environment Configuration](#οΈ-environment-configuration)
- [π Output Formats](#-output-formats)
- [π Project Structure](#-project-structure)
- [π License](#-license)
- [π€ Contributions](#-contributions)
## π‘ Why Use ScrapeSome?
- Handles both static and JS-heavy pages out of the box
- Supports both sync and async scraping
- Converts raw HTML into clean text, JSON, or Markdown
- Works with minimal configuration (`pip install scrapesome`)
- Handles timeouts, retries, redirects, user agents
## π Features
- π Sync + Async scraping support
- π Automatic retries and intelligent fallbacks
- π§ͺ Playwright rendering fallback for JS-heavy pages
- π Format responses as raw HTML, plain **text**, **Markdown**, or structured **JSON**
- βοΈ Configurable: timeouts, redirects, user agents, and logging
- π§ͺ Test coverage with `pytest` and `pytest-asyncio`
---
## β Comparison with Alternatives
| Feature | ScrapeSome β
| Playwright (Python) | Selenium + UC | Requests-HTML | Scrapy + Playwright |
|----------------------------------|--------------------------------------|-----------------------------|------------------------------|-----------------------------|------------------------------|
| π§ JS Rendering Support | β
Auto fallback on 403/JS content | β
Always (manual control) | β
Always (manual control) | β
Partial (via Pyppeteer) | β
Requires setup |
| π Automatic Fallback (403/Blank)| β
Yes (seamless) | β Manual logic needed | β Manual logic needed | β No | β Needs per-request config |
| π Uses Browser Engine | β
Only when needed (Playwright) | β
Always | β
Always | β
(Unstable, slow) | β
Always (if enabled) |
| β
Sync + Async Support | β
Built-in | β Async only | β Manual (via threading) | β Sync only | β Async only (via plugin) |
| π JSON/Markdown/HTML Output | β
Built-in formats | β Manual parsing | β Manual parsing | β Basic only | β Custom pipeline needed |
| β‘ Minimal Setup | β
Near zero | β Code + browser install | β Driver + setup | β
Simple pip install | β Complex + plugin setup |
| π Retries, Timeouts, Agents | β
Smart defaults built-in | β Manual handling | β Manual handling | β Limited | β οΈ Partial via settings |
| π§ͺ Pytest-Ready Out-of-the-box | β
Fully testable | β οΈ Requires mocks | β Hard to test | β Minimal | β οΈ Needs testing harness |
| βοΈ Config via .env / Inline | β
Flexible and optional | β Code/config only | β Manual via code | β Hardcoded mostly | β οΈ Project settings |
| π¦ Install & Run in <1 Min | β
Yes | β Setup required | β Driver + config needed | β
Yes | β Needs project + plugin |
## π¦ Installation
```bash
pip install scrapesome
```
## Playwright Setup
ScrapeSome uses Playwright for JavaScript rendering fallback. To enable this, you need to install Playwright and its dependencies.
### 1. Install Playwright Python package if not installed
```bash
pip install playwright
```
### 2. Install Playwright browsers
```bash
playwright install
```
### 3. Install system dependencies
Playwright requires some system libraries to run browsers, which vary by operating system.
For Windows
Playwright installs everything you need automatically with playwright install, so no additional setup is usually required.
For Linux (Ubuntu/Debian)
Run the following command to install required system libraries:
```bash
playwright install-deps
```
If you don't have playwright CLI available, you can install dependencies manually:
```bash
sudo apt-get update
sudo apt-get install -y libwoff1 libopus0 libwebp6 libharfbuzz-icu0 libwebpmux3 \
libenchant-2-2 libhyphen0 libegl1 libglx0 libgudev-1.0-0 \
libevdev2 libgles2 libx264-160
```
Note: Package names may vary depending on your distribution and version.
For macOS
You can install required libraries using Homebrew:
```bash
brew install harfbuzz enchant
```
After this setup, you should be able to use ScrapeSome with full Playwright rendering support!
## β‘ Quick Start
Synchronous Example
```python
from scrapesome import sync_scraper
html = sync_scraper("https://example.com")
html
```
Asynchronous Example
```python
import asyncio
from scrapesome import async_scraper
html = asyncio.run(async_scraper("https://example.com"))
html
```
## π₯οΈ CLI Usage
ScrapeSome also includes a powerful CLI for quick and easy scraping from the command line.
### π¦ Installation with CLI Support
To use the CLI, install with the optional `cli` extras:
```bash
pip install scrapesome[cli]
```
### π§ Basic Usage
```bash
scrapesome scrape --url https://example.com
```
This performs a synchronous scrape and outputs plain text by default.
### βοΈ Available Options
| Option | Description | Default |
|--------------------|-------------------------------------------|---------|
| `--async-mode` | Use asynchronous scraping | False |
| `--force-playwright`| Force JavaScript rendering using Playwright | False |
| `--output-format` | Choose `text`, `json`, `markdown`, or `html` | html |
### Examples
#### Basic scrape
```bash
scrapesome scrape --url https://example.com
```
#### Force Playwright rendering
```bash
scrapesome scrape --url https://example.com --force-playwright
```
#### Get JSON output
```bash
scrapesome scrape --url https://example.com --output-format json
```
#### Async scrape with markdown output
```bash
scrapesome scrape --url https://example.com --async-mode --output-format markdown
```
## π File Saving
ScrapeSome allows you to format and save your scraped content with zero hassleβboth via the **CLI** and in **Python code**.
---
### π» Save Output to File
Use these flags to save your output directly from the command line:
- `--save-to-file` or `-s`: Enable saving to a file
- `--file-name` or `-n`: Desired filename (extension added automatically)
- `--output-format` or `-f`: One of `html`, `text`, `markdown`, or `json`
β οΈ **Note:** When saving to a file, only one URL can be scraped at a time.
#### π¦ Example:
```bash
scrapesome scrape --url "https://example.com" --output-format markdown --save-to-file --file-name output
```
π This saves the result as `output.md`.
---
### Save Output in Code
The `sync_scraper` function supports saving to file using two optional flags:
- `save_to_file=True`: Enables saving
- `file_name="your_file_name"`: Sets the base filename (extension inferred from format)
The output will be returned as a dictionary:
```bash
{
"data": "",
"file": "your_file_name." # if saving is enabled
}
```
#### π Example:
```python
result = sync_scraper(url="https://example.com", output_format_type="json", save_to_file=True, file_name="example_output")
print(f"Saved output to {result.get('file')}")
```
Now you're set to save clean, readable data in your preferred formatβprogrammatically or from the CLI.
## π§° Advanced Usage
Force Rendering (Playwright)
```python
from scrapesome import sync_scraper
content = sync_scraper("https://example.com", force_playwright=True)
content
```
Custom User Agents
```python
from scrapesome import sync_scraper
content = sync_scraper("https://example.com", user_agents=["MyCustomAgent/1.0"])
content
```
Control Redirects
```python
from scrapesome import sync_scraper
content = sync_scraper("https://example.com", allow_redirects=False)
content
```
similarly **async_scraper** can also be used.
## π§ͺ Testing
Run tests with:
```bash
pytest --cov=scrapesome tests/
```
Target coverage: 75β100%
## βοΈ Environment Configuration
ScrapeSome reads from environment variables if a .env file is present.
Example .env
```env
LOG_LEVEL=INFO
OUTPUT_FORMAT=text
FETCH_PLAYWRIGHT_TIMEOUT=10
FETCH_PAGE_TIMEOUT=10
USER_AGENTS=["Mozilla/5.0 (Windows NT 10.0; Win64; x64)......."]
```
| Key | Description |
|--------------------------|------------------------------------------------------|
| FETCH_PLAYWRIGHT_TIMEOUT | Timeout for Playwright-rendered pages (in seconds) |
| FETCH_PAGE_TIMEOUT | Timeout for standard page fetch (in seconds) |
| LOG_LEVEL | Logging verbosity (DEBUG, INFO, WARNING, etc.) |
| OUTPUT_FORMAT | Default output format (text, markdown, json, html) |
| USER_AGENTS | Default user agents ("Mozilla/5.0 (Windows NT 10.0; Win64; x64).......") |
## π Output Formats
JSON Example
Get `json` version
```python
from scrapesome import sync_scraper
content = sync_scraper("https://example.com", output_format_type="json")
content
```
Output
```json
{
"title": "Example Domain",
"description": "This domain is for use in illustrative examples.",
"url": "https://example.com"
}
```
## Markdown
Convert HTML to Markdown with:
```python
from scrapesome import sync_scraper
content = sync_scraper("https://adenuniversity.us", output_format_type="markdown")
content
```
Output
```text
# Online Global Masters that boost your global career
**ADENΒ University** offers students access to professionals who operate in the world of business and administration, who share their knowledge and acumen collaboratively with their students in all **academic programs** offered at ADEN.
[About Us](about-aden-university)
Watch testimonial video
##### Watch testimonial video
Γ
[
](https://res.cloudinary.com/cruminott/video/upload/vc_auto,w_auto,q_auto,f_auto/adenu/aden-university-3.mp4)
## ADEN University offers the following academic programs
[](https://adenuniversity.us/academics/executive-mba/ "EXECUTIVE MBA. Master of Business Administration")
##### [EXECUTIVE MBA. Master of Business Administration](https://adenuniversity.us/academics/executive-mba/ "EXECUTIVE MBA. Master of Business Administration")
The ADEN University Executive MBA is designed to strengthen business leaders to manage...
* **37** credits
* **15** months
* **Spanish Only**
[Visit EMBA Course](https://adenuniversity.us/academics/executive-mba/ "EXECUTIVE MBA. Master of Business Administration")
[](https://adenuniversity.us/academics/global-mba/ "GLOBAL MBA. Master of Business Administration")
##### [GLOBAL MBA. Master of Business Administration](https://adenuniversity.us/academics/global-mba/ "GLOBAL MBA. Master of Business Administration")
The Global MBA is designed to prepare business leaders to manage companies in an...
* **36** credits
* **14** months
* **Spanish and English**
```
similarly **async_scraper** can also be used.
## π Project Structure
```text
scrapesome/
βββ .gitignore
βββ pytest.ini
βββ mkdocs.yml
βββ .github/
β βββ workflows/
β β βββ deploy.yml
β βββ ISSUE_TEMPLATE/
β β βββ index.md
β βββ PULL_REQUEST_TEMPLATE.md
β βββ CODE_OF_CONDUCT.md
β βββ SECURITY.md
βββ __init__.py
βββ cli.py
βββ config.py
βββ exceptions.py
βββ formatter/
β βββ __init__.py
β βββ output_formatter.py
βββ logging.py
βββ scraper/
β βββ __init__.py
β βββ async_scraper.py
β βββ sync_scraper.py
β βββ rendering.py
βββ utils/
β βββ __init__.py
β βββ file_writer.py
βββ docs/
β βββ index.md
β βββ getting_started.md
β βββ usage.md
β βββ config.md
β βββ examples.md
β βββ cli.md
β βββ about.md
β βββ licence.md
β βββ file-saving.md
β βββ contribution.md
β βββ output-formats.md
β βββ assets/
β βββ images/
β βββ favicon.png
βββ tests/
β βββ __init__.py
β βββ test_sync_scraper.py
β βββ test_async_scraper.py
β βββ test_config.py
β βββ test_logging.py
β βββ test_rendering.py
β βββ test_file_writer.py
β βββ test_output_formatter.py
β βββ test_cli.py
βββ setup.py
βββ requirements.txt
βββ pyproject.toml
βββ LICENSE
βββ README.md
```
## π License
MIT License Β© 2025
## π€ Contributions
Contributions are welcome! Whether it's bug reports, feature suggestions, or pull requests β your help is appreciated.
To get started:
```bash
git clone https://github.com/scrapesome/scrapesome.git
cd scrapesome
```
## Community
- [Contributing Guidelines](./docs/contribution.md)
- [Code of Conduct](.github/CODEOFCONDUCT.md)
- [Issue Templates](.github/issue_templates/index.md)
- [Pull Request Templates](.github/pull_request_template.md)
- [GitHub Discussions](https://github.com/scrapesome/scrapesome/discussions)