Skip to main content

Webscraperr

This Python library is designed to facilitate the common workflow of web scraping, particularly for e-commerce websites. It provides a structured framework where users can define their own logic for gathering product URLs, parsing individual product pages, and selecting the next page. The URLs and product info are saved directly to a database. It supports various databases such as SQLite and MySQL.

Installation

Install webscraperr with pip

    pip install webscraperr

Usage

The configurations of the scraper is stored in a config dictionary. The config must be prepared, modified and validated before passing it to the scraper.

from webscraperr.config import get_default_config, validate_config, DBTypes

config = get_default_config()
config['DATABASE']['TYPE'] = DBTypes.SQLITE
config['DATABASE']['DATABASE'] = 'mydatabase.db'
config['DATABASE']['TABLE'] = 'products' # If TABLE is not set "items" will be the defaut table name
config['SCRAPER']['REQUEST_DELAY'] = 1.6

validate_config(config) # Will raise an error if config is not properly set

After preparing and validating the config, you must initialize the database

from webscraperr.db import init_sqlite

init_sqlite(config['DATABASE'])

# This will create the database and the table

For this example we are going to use WebScraperRequest. This scrapper will be using requests library for the http requests. You will need to define the functions for parsing the html. There is also WebScraperChrome that uses selenium-wire and undetected-chromedriver.

from webscraperr import WebScraperRequest
from urllib.parse import urljoin
import parsel

urls = ["https://webscraper.io/test-sites/e-commerce/static/computers/tablets"]

# The `get_next_page_func` must return a url or None. If it returns None it means there is no next page

def get_next_page_func(response):
    selector = parsel.Selector(text=response.text) # in this example `parsel` is used for parsing the html
    next_page_url = selector.css('a[rel="next"]::attr(href)').get()
    if next_page_url is not None:
        return urljoin(BASE_URL, next_page_url)
    return None

# The `parse_info_func` must return a `dict`.

def parse_info_func(response):
    selector = parsel.Selector(text=response.text)
    info = {
        'name': selector.css(".caption h4:nth-child(2)::text").get(),
        'price': selector.css(".caption .price::text").get()
    }
    return info


with WebScraperRequest(config) as scraper:
    scraper.get_items_urls_func = lambda selector : [urljoin(BASE_URL, i) for i in selector.css(".thumbnail a::attr(href)").getall()]
    scraper.get_next_page_func = get_next_page_func
    scraper.parse_info_func = parse_info_func

    scraper.scrape_items_urls(urls) # This will start the scraping of products urls

    scraper.scrape_items_infos() # This will navigate to the product page and parse the html

Development Status

Please note that this library is still under development and may be subject to changes. I am constantly working on improving its functionality, flexibility and performance. Your patience, feedback, and contributions are much appreciated.

Release files for webscraperr 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for webscraperr 0.1.8
File Size Uploaded
webscraperr-0.1.8.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for webscraperr 0.1.8
File Interpreter ABI Platform
webscraperr-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / webscraperr-0.1.8.tar.gz

Download URL webscraperr-0.1.8.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2ed0fff2ff4f648a3a544a18207ac20b219f2e3489b9567a7dc94e65ca6f6648
BLAKE2b-256 checksum
How to use checksums
cccd1d9a3f058f32a2eec977f87a64ae806c4563dc9483fb93cc61075451a8b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / webscraperr-0.1.8-py3-none-any.whl

Download URL webscraperr-0.1.8-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2386c713cf466e16d6af18edc9dd066f8ddeec33651e055d604bc58dd1e5df5
BLAKE2b-256 checksum
How to use checksums
eafbdeff554eadc9c76e9c95f962b0652baa686f8da76a5db436b966d5e1ca15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page