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.Implementation Details
Implementation Details
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.Key Features
Key Features
- 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
markdownifyfor clean text formatting - User-agent spoofing: Mimics Firefox browser to avoid bot detection
Content Cleaning
Content Cleaning
The tool removes unnecessary elements:
<script>tags<style>tags<noscript>tags<link>tags<head>sections<image>and<img>tags
Structured Web Scraping
For preserving document structure, use the structured scraping tool that maintains hierarchy and optionally summarizes the content.Output Format
Output Format
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.
Cleaning Process
Cleaning Process
Usage in Agents
Advanced Agent Example
TheAdvancedAgent 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_scrape4
Analyze
Feed scraped content to LLM for probability estimation
Tool Schema
For microchain agents or function calling:Error Handling
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.