Welcome to the Correos CL Postal Code Scraper! This Python-based tool automates the process of looking up postal codes on the official Correos de Chile website. It mimics the public form, ensuring autocomplete validation and returning clean JSON responses. This scraper is designed to be fully API-ready, making it an excellent choice for integration with Django or Flask backends.
- Automated Postal Code Lookup: Quickly fetch postal codes without manual input.
- Autocomplete Validation: The scraper ensures that inputs are validated against the official form.
- Clean JSON Output: Responses are structured in a JSON format, making them easy to work with.
- API-Ready: Seamlessly integrate with Django or Flask applications.
- Headless Browser: Utilizes Playwright for efficient web scraping.
- Cross-Platform: Works on any system that supports Python.
To get started with the Correos CL Postal Code Scraper, you need to have Python 3.8 or higher installed on your machine. You can install the necessary dependencies using pip.
-
Clone the repository:
git clone https://github.com/Matteuzzz/correos-cl-postal-code-scraper.git cd correos-cl-postal-code-scraper
-
Install the required packages:
pip install -r requirements.txt
To use the scraper, you need to execute the main script. The script will take the postal code as input and return the corresponding information in JSON format.
python scraper.py <postal_code>
Replace <postal_code>
with the actual postal code you want to look up.
The scraper uses Playwright, a powerful web automation library, to interact with the Correos de Chile website. Here’s a brief overview of the process:
- Initialization: The scraper initializes a headless browser instance.
- Form Simulation: It navigates to the postal code lookup form and fills in the required fields.
- Autocomplete Handling: The scraper waits for the autocomplete suggestions to load, ensuring accurate results.
- Data Extraction: Once the postal code is validated, the scraper extracts the relevant data.
- JSON Response: Finally, the data is structured into a clean JSON format and returned.
This scraper is designed to be easily integrated into your web applications. Here’s a basic example of how you can set it up with Flask:
from flask import Flask, request, jsonify
from scraper import PostalCodeScraper
app = Flask(__name__)
@app.route('/api/postal-code', methods=['GET'])
def get_postal_code():
postal_code = request.args.get('code')
scraper = PostalCodeScraper()
result = scraper.lookup(postal_code)
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)
In this example, a GET request to /api/postal-code?code=<postal_code>
will return the postal code information in JSON format.
We welcome contributions to improve the Correos CL Postal Code Scraper. Here’s how you can help:
- Fork the repository: Create your own copy of the project.
- Create a branch: Make a new branch for your feature or bug fix.
- Make your changes: Implement your changes and test them.
- Submit a pull request: Once you're happy with your changes, submit a pull request for review.
Please ensure your code follows the project's coding standards and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for details.
You can find the latest releases of the Correos CL Postal Code Scraper here. Download the latest version and follow the installation instructions to get started.
The Correos CL Postal Code Scraper is a powerful tool for anyone needing to automate postal code lookups in Chile. Its clean JSON output and API-ready design make it suitable for various applications. Whether you are building a web app or just need quick access to postal codes, this scraper can simplify your workflow.
For further information and updates, feel free to check the Releases section.
Happy scraping!