Lego AI Parser: A Powerful Tool for Parsing HTML with AI
Lego AI Parser is an innovative open-source application designed to streamline the parsing of HTML elements by harnessing the power of OpenAI. Developed using FastAPI, this tool is versatile and ready to serve as a server, enabling users to make requests from any programming language. It simplifies the process of extracting visible text from HTML, making it accessible to developers across different platforms.
Key Features
Supported Preset Parsers
Lego AI Parser comes with a set of useful preset parsers tailored for specific platforms, including:
- Google Local Results
- Amazon Listings
- Etsy Listings
- Wayfair Listings
- BestBuy Listings
- Costco Listings
- Macy's Listings
- Nordstrom Listings
These preset parsers allow users to easily extract relevant information from popular e-commerce and local search platforms.
How to Use Lego AI Parser
Basic Usage
-
Copy the Outer HTML: Start by copying the outer HTML of the element you want to parse.
-
Acquire an OpenAI API Key: You need an API key from OpenAI, which you can obtain by registering for a free account. Your API Key can be found in your OpenAI account's API Keys section.
-
Make a POST Request: Use your API key to make a POST request to the specified endpoint. This request should include the path to the parser and the HTML elements you wish to parse.
Here is an example:
import requests
uri = "https://yourserver.com/classify"
headers = {"Content-Type": "application/json"}
data = {
"path": "your_parser_path",
"targets": ["your_html_element"],
"openai_key": "<OPENAI_KEY>"
}
response = requests.post(url=uri, headers=headers, json=data)
print(response.json()["results"])
The result will be a structured output containing the parsed data, such as address, description, rating, and more.
Parsing Multiple Elements
Lego AI Parser supports parsing multiple elements simultaneously. You can pass a mix of raw text and HTML, and the parser will handle the separation of prompts and maintain the order of results.
Designing Custom Parsers
In addition to using preset parsers, Lego AI Parser allows users to create custom parsers. By providing specific prompts, model details, and examples, users can tailor the parser to meet their unique needs. This customization allows greater flexibility, aligning the parser's performance with specific use cases.
Making Server-Side Calls Without Exposing API Key
For security and convenience, Lego AI Parser supports making server-side calls to OpenAI without exposing the API key. This feature ensures that sensitive information remains protected while still accessing the powerful parsing capabilities.
Contributions and Further Development
Lego AI Parser encourages community contributions. Developers interested in enhancing the project can add new preset parsers, conduct unit testing, and follow the contributions guide for structured collaboration.
By offering a robust set of features and flexibility, Lego AI Parser serves as an invaluable tool for developers looking to simplify the parsing of web content using AI. Whether using preset or custom parsers, users can leverage the ease of setup and powerful AI capabilities to achieve their parsing needs efficiently.