Skip to main content

Overview

The Gnosis Prediction Market Agent provides multiple web scraping tools for extracting content from URLs. These tools offer different levels of processing, from raw text extraction to structured summaries, making them suitable for various use cases in market research and prediction analysis.

Available Tools

Basic Web Scraping

The basic web scraping tool extracts text from a URL and optionally summarizes it using GPT if the content exceeds 10,000 characters.
The web_scrape function uses:
  • BeautifulSoup for HTML parsing
  • LangChain’s map-reduce chain for intelligent summarization
  • Recursive text splitting with 10,000 character chunks and 500 character overlap
  • OpenAI GPT for generating objective-focused summaries

Markdown Web Scraping

This tool converts HTML content to clean markdown format with automatic retry logic and caching.
This function is cached for 1 day using db_cache and includes automatic retries with exponential backoff.
  • Automatic retry: Up to 3 attempts with 1-second delays
  • Database caching: Results cached for 24 hours
  • Clean extraction: Removes scripts, styles, images, and other non-content elements
  • Markdown conversion: Uses markdownify for clean text formatting
  • User-agent spoofing: Mimics Firefox browser to avoid bot detection
The tool removes unnecessary elements:
  • <script> tags
  • <style> tags
  • <noscript> tags
  • <link> tags
  • <head> sections
  • <image> and <img> tags
Text is then converted to markdown and whitespace is normalized.

Structured Web Scraping

For preserving document structure, use the structured scraping tool that maintains hierarchy and optionally summarizes the content.
Unlike other scrapers that return plain text, this tool preserves hierarchical structure:
This format is ideal for extracting structured data like tables, lists, and nested content.

Usage in Agents

Advanced Agent Example

The AdvancedAgent demonstrates real-world usage of web scraping for market predictions:
1

Search

Use Google to find relevant URLs for the market question
2

Filter

Remove duplicate or low-quality sources
3

Scrape

Extract content from top URLs using web_scrape
4

Analyze

Feed scraped content to LLM for probability estimation

Tool Schema

For microchain agents or function calling:

Error Handling

Always handle potential errors when scraping:
  • Network timeouts
  • HTTP errors (404, 403, etc.)
  • Invalid HTML
  • Rate limiting

Best Practices

Use Caching

The markdown scraper includes built-in caching. For custom scrapers, use @db_cache decorator to avoid redundant requests.

Set Timeouts

Always specify timeouts to prevent hanging requests. Default is 10 seconds.

Handle Failures

Use the tool_exception_handler for graceful error handling in production agents.

Respect Limits

Implement rate limiting and respect robots.txt when scraping multiple pages.

Dependencies

All web scraping tools require valid API keys. Set OPENAI_API_KEY in your environment for summarization features.