by moonboy
Selenium AI Scraper with Google Gemini Flash
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)
Created: | Last Updated:
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:
- Click "Start with this Template" in the Lazy Builder interface.
- 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:
- Open the provided server link in your web browser.
- You'll see a form with two input fields:
- URL: Enter the webpage URL you want to scrape.
- Question: Enter the question you want to answer based on the webpage content.
- Click the "Submit" button to process your request.
- 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:
- Answer: A detailed response to your question based on the webpage content.
- HTML Element: The specific HTML tag containing the answer on the webpage.
- 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.