Skip to main content

Web Scraper for Static and JS Rendered Sites

This repository contains a versatile web scraper capable of handling both statically rendered HTML sites and dynamically rendered JavaScript sites. By combining techniques for traditional HTML scraping with methods for interacting with JavaScript-heavy websites, this single program offers a comprehensive solution for extracting data from a wide range of web sources.

Features

  • Dual Scraping Modes: Can processes static HTML or JS-rendered content.
  • Headless Browser Support: Utilizes headless browsers to render and scrape JavaScript-heavy sites.
  • Easy Configuration: Simple setup and configuration to specify target URLs and data extraction rules.
  • Efficient Data Extraction: Optimized for speed and reliability, ensuring accurate data retrieval.

Usage

1. Modify the config.yaml file as per your requirement.

  • The configuration should follow same format as shown in config.yaml by default as a sample.
  • The terminator key in configuration is optional. Only required if you have a specific terminating point to stop scraping.
  • The path key can have multiple values, in case you want to extract elements from multiple css-selectors.
  • The depth of configuration does not matter as long as the depth ends with the key path.

Here's the sample configuration for you:

<YOUR_VENDOR_NAME>:
  base:
    url: <URL_OF_THE_SITE_FROM-WHERE_YOU_WANT_TO_EXTRACT_ALL_URLS>
    path:
      - <PATH_TO_SINGLE_URL_ELEMENT>
  content:
    <CONTENT_SECTION_1>:
      path:
        - <YOUR_CSS_SELECTOR_PATH>
      terminator: <YOUR_CSS_SELECTOR_PATH_TO_TERMINATING_POINT>
    <CONTENT_SECTION_2>:
      path:
        - <YOUR_CSS_SELECTOR_PATH>
      terminator: <YOUR_CSS_SELECTOR_PATH_TO_TERMINATING_POINT>

2. Run the following code

To get the JS-Rendered Content using Headless browser, follow along with the code below:

import asyncio

from tqdm import tqdm

from scrapeall.parse import HTMLParser


async def main(vendor: str, config_path: str):
    data = dict()

    parser = HTMLParser(vendor, config_path)
    await parser.initialize_browser()
    await parser.get_all_urls()
    for key, url in tqdm(parser.urls.items()):
        await parser.get_content(url)
        data[key] = parser.data

    await parser.close_browser()
    return data


if __name__ == "__main__":
    VENDOR = "<YOUR_VENDOR_NAME>"
    CONFIG_PATH = "<PATH_TO_YOUR_YAML_FILE>"
    data = asyncio.run(main(VENDOR, CONFIG_PATH))

To get the Content from static HTML sites/pages, modify the main function as follows:

async def main(vendor: str, config_path: str):
    data = dict()

    parser = HTMLParser(vendor, config_path)
    await parser.get_all_urls()
    for key, url in tqdm(parser.urls.items()):
        await parser.get_content(url)
        data[key] = parser.data
    return data

If you want to save the content scrapped, you can do that by following the given code snippet:

import asyncio

from tqdm import tqdm

from scrapeall.utils import save_data
from scrapeall.parse import HTMLParser


async def main(vendor: str, config_path: str, output_file: str = ""):
    data = dict()

    parser = HTMLParser(vendor, config_path)
    await parser.initialize_browser()
    await parser.get_all_urls()
    for key, url in tqdm(parser.urls.items()):
        await parser.get_content(url)
        data[key] = parser.data

    await parser.close_browser()
    if output_file:
        await save_data(filename=output_file, data=data)
    return data


if __name__ == "__main__":
    VENDOR = "<YOUR_VENDOR_NAME>"
    CONFIG_PATH = "<PATH_TO_YOUR_YAML_FILE>"
    OUTPUT_FILE = "<PATH_TO_YOUR_JSON_FILE>"
    data = asyncio.run(main(VENDOR, CONFIG, OUTPUT_FILE))

Remember: YOUR_VENDOR_NAME should match one in the <CONFIG_PATH>.yaml file.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your enhancements or bug fixes.

Metadata

Release files for scrapeall 0.1.2

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

Source distribution (sdist)

Source distribution for scrapeall 0.1.2
File Size Uploaded Provenance Actions
scrapeall-0.1.2.tar.gz 4.3 kB Without provenance Details for scrapeall-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 9.0 kB

Release files / scrapeall-0.1.2.tar.gz

Download URL scrapeall-0.1.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a32a9b42caadf86b9687052d7be6b656a8d39fbf5607982028eaa5de7d01b238
BLAKE2b-256 checksum
How to use checksums
73fab13ca47d7835bcec88fae8783b02a6ec4872f1d3308a0f204eb5b9f01d95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / scrapeall-0.1.2-py3-none-any.whl

Download URL scrapeall-0.1.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
181121f4e5dc1c508a74fcdfe8a25e87381547860943e18fce037d4887f0f21b
BLAKE2b-256 checksum
How to use checksums
2ed25322acd7d49ae65f74bd0441b09f9de9d365c87cd32365f343cfbc0eb9c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for scrapeall 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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