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.

Requirements

To install the dependencies for this project, use the provided requirements.yaml file for setting up a conda environment.

Install the Dependencies

  1. Clone the repository:

    git clone https://github.com/yourusername/rufus_crawler.git
    cd rufus_crawler
    
  2. Install Conda if you haven't already, then create a new environment using requirements.yaml:

    conda env create -f requirements.yaml
    conda activate rufus-crawler
    
  3. Install the Rufus Crawler package in editable mode for development:

    pip install -e .
    

Project Structure

rufus_crawler/
├── rufus/
   ├── client.py             # Main RufusClient class
   ├── filter.py             # ContentFilter class
├── scripts/
   ├── run_rufus.py          # Script to execute the crawler
├── crawled_data/             # Folder 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)

Setup

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 to add your OpenAI API key, target URL, and instructions.

    In scripts/run_rufus.py:

    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"
    
  3. 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.

Example Output

[
    {
        "URL": "https://www.uta.edu/admissions/apply/graduate",
        "content": "GPT-filtered content related to the admission process."
    },
    {
        "URL": "https://www.uta.edu/admissions/contact",
        "content": "GPT-filtered content providing contact details for admissions."
    }
]

Cleaning Up

After execution, the script automatically deletes the intermediate .txt files and directories, leaving only the filtered_data.json file with the relevant content.

Known Issues

  • Dynamic Content: Some dynamic content may take longer to load, so increasing the sleep time in the selenium_get_page_content() method might help if certain content is missing.
  • Rate Limiting: OpenAI has rate limits, so ensure you have adequate API limits or handle API exceptions gracefully.

Contributing

Contributions are welcome! If you'd like to contribute to this project, feel free to fork the repository and submit a pull request.

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.0.tar.gz (7.2 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.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rufus_crawler-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 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.0.tar.gz
Algorithm Hash digest
SHA256 a4c4e64520bf39ff8949335dcde1af0fd81e113bf6f818c7004bebdd1fe75a4c
MD5 a2606df7eb30812d9fc20470b90953d6
BLAKE2b-256 b09fde0ac851806a760ade8872661fa649a837e2491a0b75518a965ed2fcba2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rufus_crawler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cccf0a31f4b17c089b5bb8879b94a25b412340744f9d7b00f719f0fec066840b
MD5 d67c3209232c8c329e2c97d5f60c5bb0
BLAKE2b-256 84d75aaec15420319ca0d2d9b79a91a50032ca18d3370d2f69c384dc6a63ce2f

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