|
| 1 | +--- |
| 2 | +title: "News-Use (News Monitor)" |
| 3 | +description: "Monitor news websites and extract articles with sentiment analysis using browser agents and Google Gemini." |
| 4 | +icon: "newspaper" |
| 5 | +mode: "wide" |
| 6 | +--- |
| 7 | + |
| 8 | +<Note> |
| 9 | +This demo requires browser-use v0.7.7+. |
| 10 | +</Note> |
| 11 | + |
| 12 | +<video |
| 13 | + controls |
| 14 | + className="w-full aspect-video rounded-xl" |
| 15 | + src="https://github.com/user-attachments/assets/650843ee-0b4d-431a-983f-6c1af3d0ffd8"> |
| 16 | +</video> |
| 17 | + |
| 18 | +## Features |
| 19 | + |
| 20 | +1. Agent visits any news website automatically |
| 21 | +2. Finds and clicks the most recent headline article |
| 22 | +3. Extracts title, URL, posting time, and full content |
| 23 | +4. Generates short/long summaries with sentiment analysis |
| 24 | +5. Persistent deduplication across monitoring sessions |
| 25 | + |
| 26 | +## Setup |
| 27 | + |
| 28 | +Make sure the newest version of browser-use is installed: |
| 29 | +```bash |
| 30 | +pip install -U browser-use |
| 31 | +``` |
| 32 | + |
| 33 | +Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.google.com/app/apikey) |
| 34 | +```bash |
| 35 | +export GEMINI_API_KEY='your-google-api-key-here' |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage Examples |
| 39 | + |
| 40 | +```bash |
| 41 | +# One-time extraction - Get the latest article and exit |
| 42 | +python news_monitor.py --once |
| 43 | +
|
| 44 | +# Monitor Bloomberg continuously (default) |
| 45 | +python news_monitor.py |
| 46 | +
|
| 47 | +# Monitor TechCrunch every 60 seconds |
| 48 | +python news_monitor.py --url https://techcrunch.com --interval 60 |
| 49 | +
|
| 50 | +# Debug mode - See browser in action |
| 51 | +python news_monitor.py --once --debug |
| 52 | +``` |
| 53 | + |
| 54 | +## Output Format |
| 55 | + |
| 56 | +Articles are displayed with timestamp, sentiment emoji, and summary: |
| 57 | + |
| 58 | +``` |
| 59 | +[2025-09-11 02:49:21] - 🟢 - Klarna's IPO raises $1.4B, benefiting existing investors |
| 60 | +[2025-09-11 02:54:15] - 🔴 - Tech layoffs continue as major firms cut workforce |
| 61 | +[2025-09-11 02:59:33] - 🟡 - Federal Reserve maintains interest rates unchanged |
| 62 | +``` |
| 63 | + |
| 64 | +**Sentiment Indicators:** |
| 65 | +- 🟢 **Positive** - Good news, growth, success stories |
| 66 | +- 🟡 **Neutral** - Factual reporting, announcements, updates |
| 67 | +- 🔴 **Negative** - Challenges, losses, negative events |
| 68 | + |
| 69 | +## Data Persistence |
| 70 | + |
| 71 | +All extracted articles are saved to `news_data.json` with complete metadata: |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "hash": "a1b2c3d4...", |
| 76 | + "pulled_at": "2025-09-11T02:49:21Z", |
| 77 | + "data": { |
| 78 | + "title": "Klarna's IPO pops, raising $1.4B", |
| 79 | + "url": "https://techcrunch.com/2025/09/11/klarna-ipo/", |
| 80 | + "posting_time": "12:11 PM PDT · September 10, 2025", |
| 81 | + "short_summary": "Klarna's IPO raises $1.4B, benefiting existing investors like Sequoia.", |
| 82 | + "long_summary": "Fintech Klarna successfully IPO'd on the NYSE...", |
| 83 | + "sentiment": "positive" |
| 84 | + } |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +## Programmatic Usage |
| 89 | + |
| 90 | +```python |
| 91 | +import asyncio |
| 92 | +from news_monitor import extract_latest_article |
| 93 | +
|
| 94 | +async def main(): |
| 95 | + # Extract latest article from any news site |
| 96 | + result = await extract_latest_article( |
| 97 | + site_url="https://techcrunch.com", |
| 98 | + debug=False |
| 99 | + ) |
| 100 | + |
| 101 | + if result["status"] == "success": |
| 102 | + article = result["data"] |
| 103 | + print(f"📰 {article['title']}") |
| 104 | + print(f"😊 Sentiment: {article['sentiment']}") |
| 105 | + print(f"📝 Summary: {article['short_summary']}") |
| 106 | +
|
| 107 | +asyncio.run(main()) |
| 108 | +``` |
| 109 | + |
| 110 | +## Advanced Configuration |
| 111 | + |
| 112 | +```python |
| 113 | +# Custom monitoring with filters |
| 114 | +async def monitor_with_filters(): |
| 115 | + while True: |
| 116 | + result = await extract_latest_article("https://bloomberg.com") |
| 117 | + if result["status"] == "success": |
| 118 | + article = result["data"] |
| 119 | + # Only alert on negative market news |
| 120 | + if article["sentiment"] == "negative" and "market" in article["title"].lower(): |
| 121 | + send_alert(article) |
| 122 | + await asyncio.sleep(300) # Check every 5 minutes |
| 123 | +``` |
| 124 | + |
| 125 | +## Source Code |
| 126 | + |
| 127 | +Full implementation: [https://github.com/browser-use/browser-use/tree/main/examples/apps/news-use](https://github.com/browser-use/browser-use/tree/main/examples/apps/news-use) |
0 commit comments