How to Build an AI-Powered Web Article Summarizer with Python 🐍

μž‘μ„±μž

μΉ΄ν…Œκ³ λ¦¬:

← ν”Όλ“œλ‘œ
DEV Community · Mohamed · 2026-07-18 개발(SW)

Mohamed

Hey DEV Community! πŸ‘‹

Today, I want to share a super useful Python script I built that uses AI to automatically fetch and summarize any web article. It’s perfect for saving time and automating your daily reading list!

πŸ› οΈ What This Script Does:

  1. Takes any article URL.
  2. Extracts the main text content cleanly.
  3. Uses an AI model to generate a bullet-point summary.

πŸ’» The Code


python
import requests
from bs4 import BeautifulSoup
from transformers import pipeline

def summarize_article(url):
    print("⏳ Fetching article content...")
    # 1. Fetch the webpage
    response = requests.get(url)
    if response.status_code != 200:
        return "Failed to retrieve the article."

    # 2. Parse HTML and extract text
    soup = BeautifulSoup(response.text, 'html.parser')
    paragraphs = soup.find_all('p')
    article_text = ' '.join([p.get_text() for p in paragraphs])

    # 3. Initialize the AI summarization pipeline
    print("πŸ€– Generating summary using AI...")
    summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

    # Limit text length for the model
    input_text = article_text[:2000] 

    summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
    return summary[0]['summary_text']

# Example Usage
if __name__ == "__main__":
    article_url = "https://dev.to/t/python" 
    result = summarize_article(article_url)
    print("\nπŸ“ AI Summary:")
    print(result)
---
πŸ’Ό **Need a custom Python automation tool or web scraper?** You can hire me directly on Fiverr: [Hire Me on Fiverr](https://www.fiverr.com/kabunji_uxui)

Enter fullscreen mode Exit fullscreen mode

μ›λ¬Έμ—μ„œ 계속 β†—

μ½”λ©˜νŠΈ

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€