Skip to main content

A simple web scraper library

Project description

🕷️ WebScraper

A Python library for automating repetitive web scraping tasks — built with batteries included.

Features

Module What it does
Scraper HTTP engine with retries, rate limiting, rotating User-Agents
Parser HTML extraction — text, links, tables, images, meta tags
Pipeline One-call scrape → parse → save for URL lists and paginated sites
Scheduler Schedule recurring jobs (every N seconds/minutes/hours)
Storage Save results as JSON or CSV, append, deduplicate

Installation

pip install requests beautifulsoup4 lxml
# Then copy the webscraper/ folder into your project

Quick Start

1. Fetch a page

from webscraper import Scraper, Parser

scraper = Scraper(delay=1.0)          # 1 second between requests
response = scraper.get("https://example.com")

parser = Parser(response.text)
print(parser.title())                  # → "Example Domain"
print(parser.links())                  # → ["https://..."]

2. Extract structured data

data = parser.extract({
    "title": "h1",
    "price": ".product-price",
    "images": {"selector": "img", "attr": "src", "all": True},
})
# → {"title": "Product Name", "price": "$9.99", "images": [...]}

3. Scrape multiple pages automatically

from webscraper import Pipeline, Storage

pipeline = Pipeline(
    scraper=Scraper(delay=1.5),
    storage=Storage("output"),
)

# Paginated scraping
results = pipeline.run_paginated(
    url_template="https://site.com/products?page={page}",
    start_page=1,
    end_page=10,
    extract_rules={
        "name":  "h2.product-title",
        "price": ".price",
        "link":  {"selector": "a.product-link", "attr": "href"},
    },
    output_file="products.json",
)

4. Schedule recurring scrapes

from webscraper import Scheduler

scheduler = Scheduler()

@scheduler.every(minutes=15, max_runs=96)   # every 15 min for 24h
def monitor_prices():
    scraper = Scraper()
    resp = scraper.get("https://example.com/prices")
    parser = Parser(resp.text)
    # ... extract and save

scheduler.run()   # blocking
# or: scheduler.run(blocking=False)  # background thread

API Reference

Scraper

Scraper(
    delay=1.0,           # seconds between requests
    delay_jitter=0.5,    # adds random 0–0.5s on top
    retries=3,           # auto-retry on 5xx / timeout
    timeout=30,          # request timeout
    headers={},          # custom headers
    proxies={},          # {"http": "...", "https": "..."}
    rotate_user_agents=True,
    verify_ssl=True,
)
Method Description
.get(url) GET request
.post(url, data, json) POST request
.fetch_many(urls) Fetch list of URLs
.crawl(start_url, max_pages) Follow links from start URL

Parser

Parser(html_string)
Method Description
.title() <title> text
.text(selector, all=False) Text from CSS selector
.attr(selector, attribute, all=False) Attribute value
.links(base_url) All <a href> URLs
.links_with_text() [{"url": ..., "text": ...}]
.images(base_url) [{"src": ..., "alt": ...}]
.table(index=0) Parse HTML table → list of dicts
.all_tables() All tables
.meta() All meta tags
.og_data() Open Graph tags
.body_text() All visible text
.extract(rules) Multi-field extraction
.extract() rules {"field": "selector"} or {"field": {"selector": "...", "attr": "...", "all": bool}}

Pipeline

Pipeline(scraper=None, storage=None)
Method Description
.run(urls, extract_rules, ...) Scrape a list of URLs
.run_paginated(url_template, start, end, ...) Scrape paginated URLs
.results Last run's results

Scheduler

Scheduler()
Method Description
.every(seconds, minutes, hours) Decorator to schedule a function
.add_job(func, interval_seconds, ...) Register job programmatically
.run(blocking=True) Start scheduler
.stop() Stop scheduler
.cancel(name) Cancel a job
.status() List all jobs and their state

Storage

Storage(output_dir="output")
Method Description
.save_json(data, filename) Save as JSON
.load_json(filename) Load JSON
.append_json(new_data, filename) Append to JSON array
.save_csv(data, filename) Save as CSV
.load_csv(filename) Load CSV
.append_csv(new_data, filename) Append to CSV
.deduplicate(data, key) Remove duplicates by field
.list_files() List output directory files

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_py-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_py-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file scrapy_py-0.1.0.tar.gz.

File metadata

  • Download URL: scrapy_py-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for scrapy_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8584fc43d167a2825946f5b951cef9e91ded9f7e3c343cc500c195c0a75f4fea
MD5 f3c8a426f01300eae2cbf71fdbcb5cb2
BLAKE2b-256 e3b3edc3d10a91e91b08e77dbd2d90df93af54780c954c0e00087cc6a991c1b0

See more details on using hashes here.

File details

Details for the file scrapy_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scrapy_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for scrapy_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f52e258581f60057b44e1077e84c986a162212f85f670f6b4ca807e58dd758d
MD5 aa7f72dfa2ada528ddee80fe4fccdec7
BLAKE2b-256 13d29af835f2d7cb7d2c704eec3450deca9d04570e17c24bff9c392ffbf0f174

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page