OmniScraperGraph is an advanced scraping pipeline that combines text extraction with image analysis. It uses vision-capable LLMs to describe images on the page and incorporates those descriptions into the final answer.
The OmniScraperGraph constructor accepts the following parameters:
OmniScraperGraph( prompt: str, # Natural language description including text and image requirements source: str, # URL or path to local HTML file config: dict, # Configuration dictionary schema: Optional[BaseModel] = None # Pydantic schema for structured output)
import osimport jsonfrom dotenv import load_dotenvfrom scrapegraphai.graphs import OmniScraperGraphfrom scrapegraphai.utils import prettify_exec_infoload_dotenv()openai_key = os.getenv("OPENAI_API_KEY")graph_config = { "llm": { "api_key": openai_key, "model": "openai/gpt-4o", # Must be a vision-capable model }, "max_images": 5, "verbose": True,}# Create the OmniScraperGraph instanceomni_scraper = OmniScraperGraph( prompt="List me all the attractions in Chioggia and describe their pictures.", source="https://en.wikipedia.org/wiki/Chioggia", config=graph_config,)# Run the graphresult = omni_scraper.run()print(json.dumps(result, indent=4))# Get execution infograph_exec_info = omni_scraper.get_execution_info()print(prettify_exec_info(graph_exec_info))
Limit the number of images to analyze for performance:
graph_config = { "llm": { "api_key": openai_key, "model": "openai/gpt-4o", }, "max_images": 10, # Process up to 10 images}omni_scraper = OmniScraperGraph( prompt="Describe the product images and their features", source="https://example.com/product", config=graph_config,)
Each image analysis consumes additional tokens. Higher max_images = higher cost and longer execution time.
The run() method returns combined text and image analysis:
result = omni_scraper.run()# Returns: Dictionary with both text extraction and image descriptions# or schema-validated object if schema provided# Example structure:# {# "title": "Product Name",# "description": "Text description from page",# "images": [# {# "url": "https://...",# "description": "AI-generated description of what's in the image"# }# ]# }
try: result = omni_scraper.run() if result: print("Scraping successful!") print(f"Extracted data: {result}") else: print("No data extracted")except Exception as e: print(f"Error during omni-scraping: {e}")
omni_scraper = OmniScraperGraph( prompt="Analyze all images and text in this local page", source="/path/to/local/page.html", config=graph_config,)result = omni_scraper.run()
Local images must be referenced with absolute paths or the HTML file must contain complete image URLs.
Include specific image-related instructions in your prompt:
# Good prompt for image analysisprompt = """Extract product information including:- Product name and price from text- Visual features visible in images (color, material, design)- Condition assessment from photos- Any text visible in product images"""# Not as effectiveprompt = "Extract product information"