This project is a tool that combines web scraping with language model analysis. It fetches content from a specified URL, extracts its textual information using BeautifulSoup, and then sends the content to an OpenAI LLM (using the model "gpt-4o") for a comprehensive analysis based on custom instructions provided by the user. The final analysis output is saved to output.txt.
This project was executed from start to finish using the terminal-based programming assistance software Aider (https://aider.chat/) which connected to the OpenAI "o3-mini" model via its API.
- Web Scraping: Utilizes the
requestslibrary to retrieve web pages andBeautifulSoupfrombeautifulsoup4for parsing HTML. - LLM Analysis: Integrates with OpenAI’s API (through the
openaipackage) to process and analyze scraped text. - Environment Configuration: Leverages
python-dotenvto securely manage sensitive configurations like the OpenAI API key through a.envfile. - Output Storage: Saves the processed analysis results to a file (
output.txt) for later review.
-
webscraper.py:
- Loads environment variables from
.env. - Prompts the user for a URL and an instruction prompt for the analysis.
- Scrapes the provided URL and extracts text content.
- Sends the text along with developer instructions to the OpenAI API.
- Writes the LLM’s output to
output.txt.
- Loads environment variables from
-
output.txt:
Stores the result of the LLM analysis. -
requirements.txt:
Lists all necessary dependencies:requestsbeautifulsoup4python-dotenvopenai
-
.gitignore:
Specifies files and directories to be ignored by Git (read-only, not modified by this project).
-
Clone the Repository:
git clone <repository_url> cd <repository_directory>
-
Install Dependencies:
pip install -r requirements.txt
-
Environment Configuration:
- Create a
.envfile in the project root directory. - Add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
- Create a
-
Make the Script Executable (if necessary):
chmod +x webscraper.py
Run the scraper by executing:
./webscraper.pyYou will be prompted to:
- Enter the URL to scrape.
- Enter the prompt instructions for the LLM analysis.
The analysis results will be written to output.txt and a confirmation message will be printed.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request with a clear description of your changes.
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 polimat[IA]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For further questions or contributions, please contact the project maintainer.