by moonboy

Selenium AI Scraper with Google Gemini Flash

Test this app for free
76
import json
from abilities import llm
from fastapi import Request
import logging

import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from selenium_utils import SeleniumUtility

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = FastAPI()
templates = Jinja2Templates(directory="templates")
app.mount("/static", StaticFiles(directory="static"), name="static")

@app.get("/", response_class=HTMLResponse)
async def form_page(request: Request):
    return templates.TemplateResponse("form.html", {"request": request})

@app.post("/process-page-info", response_class=HTMLResponse)
Get full code

Created: | Last Updated:

Web application to help scraping specific webpages. This selenium app sends the code of the page to Gemini flash 1.5 and asks it to retrieve the answer and points out the element on the page to do so.

Here's a step-by-step guide for using the AI Scraper with Google Gemini Flash template:

Introduction

The AI Scraper with Google Gemini Flash template is a powerful web application that helps you scrape specific webpages using Selenium and Google's Gemini 1.5 Flash AI model. This app allows you to input a URL and a question, then retrieves the relevant information from the webpage and provides you with a detailed answer, the HTML element containing the answer, and Python code to extract the answer using Selenium WebDriver.

Getting Started

To begin using this template, follow these steps:

  1. Click "Start with this Template" in the Lazy Builder interface.
  2. Press the "Test" button to deploy the application.

Using the App

Once the app is deployed, you'll receive a server link to access the web interface. Follow these steps to use the AI Scraper:

  1. Open the provided server link in your web browser.
  2. You'll see a form with two input fields:
  3. URL: Enter the webpage URL you want to scrape.
  4. Question: Enter the question you want to answer based on the webpage content.
  5. Click the "Submit" button to process your request.
  6. Wait for the AI to analyze the webpage and generate a response.

Understanding the Results

After processing your request, the app will display the following information:

  1. Answer: A detailed response to your question based on the webpage content.
  2. HTML Element: The specific HTML tag containing the answer on the webpage.
  3. Selenium Code: Python code snippet to extract the relevant content using Selenium WebDriver.

Integrating the App

This AI Scraper can be integrated into other applications or workflows. Here's a sample code snippet to make a request to the API endpoint:

```python import requests

url = "https://your-lazy-app-url.com/process-page-info" data = { "url": "https://example.com", "question": "What is the main topic of this webpage?" }

response = requests.post(url, data=data) result = response.json()

print("Answer:", result["answer"]) print("HTML Element:", result["html_element"]) print("Selenium Code:", result["selenium_code"]) ```

Replace "https://your-lazy-app-url.com" with the actual URL provided by Lazy for your deployed app.

By following these steps, you can easily use the AI Scraper with Google Gemini Flash to extract and analyze information from webpages efficiently.

Technologies

Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More Streamline CSS Development with Lazy AI: Automate Styling, Optimize Workflows and More
Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More Enhance HTML Development with Lazy AI: Automate Templates, Optimize Workflows and More
Enhance Selenium Automation with Lazy AI: API Testing, Scraping and More Enhance Selenium Automation with Lazy AI: API Testing, Scraping and More
Gemini Gemini
Python App Templates for Scraping, Machine Learning, Data Science and More Python App Templates for Scraping, Machine Learning, Data Science and More

Similar templates

FastAPI endpoint for Text Classification using OpenAI GPT 4

This API will classify incoming text items into categories using the Open AI's GPT 4 model. If the model is unsure about the category of a text item, it will respond with an empty string. The categories are parameters that the API endpoint accepts. The GPT 4 model will classify the items on its own with a prompt like this: "Classify the following item {item} into one of these categories {categories}". There is no maximum number of categories a text item can belong to in the multiple categories classification. The API will use the llm_prompt ability to ask the LLM to classify the item and respond with the category. The API will take the LLM's response as is and will not handle situations where the model identifies multiple categories for a text item in the single category classification. If the model is unsure about the category of a text item in the multiple categories classification, it will respond with an empty string for that item. The API will use Python's concurrent.futures module to parallelize the classification of text items. The API will handle timeouts and exceptions by leaving the items unclassified. The API will parse the LLM's response for the multiple categories classification and match it to the list of categories provided in the API parameters. The API will convert the LLM's response and the categories to lowercase before matching them. The API will split the LLM's response on both ':' and ',' to remove the "Category" word from the response. The temperature of the GPT model is set to a minimal value to make the output more deterministic. The API will return all matching categories for a text item in the multiple categories classification. The API will strip any leading or trailing whitespace from the categories in the LLM's response before matching them to the list of categories provided in the API parameters. The API will accept lists as answers from the LLM. If the LLM responds with a string that's formatted like a list, the API will parse it and match it to the list of categories provided in the API parameters.

Icon 1 Icon 1
251