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
.txtfiles. - 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.jsonfile.
Requirements
To install the dependencies for this project, use the provided requirements.yaml file for setting up a conda environment.
Install the Dependencies
-
Clone the repository:
git clone https://github.com/yourusername/rufus_crawler.git cd rufus_crawler
-
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
-
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.
-
OpenAI API Key: Obtain an API key from OpenAI if you don't have one.
-
Edit the
run_rufus.pyscript 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"
-
Run the crawler:
python scripts/run_rufus.py
Workflow
1. Crawling and Saving Content
- The
RufusClientcrawls the target URL recursively (depth controlled). - The dynamic content rendered by JavaScript is fetched using Selenium.
- Extracted content is saved into
.txtfiles within thecrawled_data/directory.
2. Convert TXT Files to JSON
- The text files are converted to a JSON file,
crawled_data.json.
3. Filtering Content
- The
ContentFilteruses 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
.txtfiles and directories are deleted, leaving onlyfiltered_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4c4e64520bf39ff8949335dcde1af0fd81e113bf6f818c7004bebdd1fe75a4c
|
|
| MD5 |
a2606df7eb30812d9fc20470b90953d6
|
|
| BLAKE2b-256 |
b09fde0ac851806a760ade8872661fa649a837e2491a0b75518a965ed2fcba2b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cccf0a31f4b17c089b5bb8879b94a25b412340744f9d7b00f719f0fec066840b
|
|
| MD5 |
d67c3209232c8c329e2c97d5f60c5bb0
|
|
| BLAKE2b-256 |
84d75aaec15420319ca0d2d9b79a91a50032ca18d3370d2f69c384dc6a63ce2f
|