Skip to main content

A web crawler and content filtering tool using OpenAI.

Project description

Rufus Crawler

Rufus Crawler is a Python-based web crawling and content filtering tool designed to scrape web pages, extract relevant content, and refine the data using OpenAI's GPT models. It works on dynamic web pages rendered with JavaScript using Selenium, and it allows for recursive crawling with adjustable depth limits. The resulting data is then filtered based on user-defined instructions and saved in JSON format.

Features

  • Dynamic web page crawling: Supports JavaScript-rendered web pages using Selenium.
  • Depth-controlled crawling: Crawl pages up to a user-defined depth, staying within the base domain.
  • Content extraction: Extracts text content from web pages and saves them in .txt files.
  • Filtered content: Uses OpenAI's GPT models to filter and refine the content based on user-provided instructions.
  • Output in JSON format: Final filtered content is saved in a filtered_data.json file.

Installation

You can install the package directly from PyPI:

pip install rufus_crawler

Example Usage

from rufus import RufusClient, ContentFilter

openai_api_key = "your_openai_api_key"
url = "https://example.com"
instructions = "Find information about product features and customer FAQs."

client = RufusClient(openai_api_key)
client.crawl(url, depth=2)
crawled_data = client.convert_txt_to_json()

content_filter = ContentFilter(openai_api_key)
filtered_data = content_filter.filter_content(instructions, crawled_data)
content_filter.save_filtered_data(filtered_data)

Project Structure

rufus_crawler/
├── rufus/
│   ├── client.py            # Main RufusClient class   ├── content_filter.py    # ContentFilter class   ├── config.py            # Configuration settings   ├── utils.py             # Utility functions
├── scripts/
│   ├── run_rufus.py         # Main script to run the crawler
├── crawled_data/            # Directory to store intermediate crawled data
├── filtered_data.json       # Final output after filtering
├── requirements.yaml        # Conda environment dependencies
├── setup.py                 # Project setup for pip installation
└── README.md                # Project documentation (this file)

Setting up the Environment

Use the provided requirements.yaml file to set up a Conda environment:

  1. Clone the repository:
git clone https://github.com/yourusername/rufus_crawler.git
cd rufus_crawler
  1. Install Conda if you haven't already, and then create a new environment:
conda env create -f requirements.yaml
conda activate rufus-crawler
  1. Install the Rufus Crawler package in editable mode for development:
pip install -e .

Usage

To configure the Rufus Crawler, you will need an OpenAI API key:

  1. OpenAI API Key: Obtain an API key from OpenAI if you don't have one.
  2. Edit the run_rufus.py script or your custom Python file to add your OpenAI API key, target URL, and instructions.
openai_api_key = "your_openai_api_key"  # Replace with your OpenAI API key
url = "https://www.uta.edu/admissions/apply/graduate"
instructions = "We're making a chatbot for graduate admission process for UTA"
  1. Run the crawler:
python scripts/run_rufus.py

Workflow

1. Crawling and Saving Content

  • The RufusClient crawls the target URL recursively (depth controlled).
  • The dynamic content rendered by JavaScript is fetched using Selenium.
  • Extracted content is saved into .txt files within the crawled_data/ directory.

2. Convert TXT Files to JSON

  • The text files are converted to a JSON file, crawled_data.json.

3. Filtering Content

  • The ContentFilter uses OpenAI's GPT to refine and filter the crawled content based on the provided instructions.
  • The refined data is saved into filtered_data.json.

4. Cleanup

  • After successful filtering, all intermediate .txt files and directories are deleted, leaving only filtered_data.json.

License

This project is licensed under the MIT License.

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

rufus_crawler-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

rufus_crawler-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file rufus_crawler-0.1.1.tar.gz.

File metadata

  • Download URL: rufus_crawler-0.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for rufus_crawler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9894f8eca8fa575c97ec8980f5113b2c3a2655cdf344d632ca44f817ae1ac8ac
MD5 822992fbdb542ad739418a5b7718454d
BLAKE2b-256 215427818b24cb1788d86729b7d19a39bfbfeb68c0c92c9c803a2dc01d6c0874

See more details on using hashes here.

File details

Details for the file rufus_crawler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rufus_crawler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for rufus_crawler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1090bf35aad9d672b720a92456a8e0904e3ff99a2487931a4ce8c567680f6188
MD5 1c931ce356f25b5278df9b5a9fa51cff
BLAKE2b-256 eee4483040d8d0ffa5a64b509c3b27b24beb7cbe548e8058b90dffd7e8846428

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