Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

Write some simple python code to scrape a website

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Amazon Novaamazon-nova-experimental-chat-05-14’s answer.
  1. User

    Write some simple python code to scrape a website

  2. Assistant

    Sure! Here's a simple Python script that uses the requests and BeautifulSoup libraries to scrape the titles of blog posts from a sample website.

    🚀 Goal:

    Scrape article titles from a web page.


    ✅ Prerequisites:

    Make sure you install the required libraries first:

    pip install requests beautifulsoup4
    

    🧠 Python Code:

    import requests
    from bs4 import BeautifulSoup
    
    # URL of the website you want to scrape
    url = "https://example.com"
    
    # Send a GET request to the website
    response = requests.get(url)
    
    # Check if request was successful
    if response.status_code == 200:
        # Parse the HTML content using BeautifulSoup
        soup = BeautifulSoup(response.text, 'html.parser')
    
        # Find all the article titles (Example: assuming <h2> tags with class 'post-title')
        titles = soup.find_all('h2', class_='post-title')
    
        # Print each title
        for title in titles:
            print(title.get_text(strip=True))
    else:
        print("Failed to retrieve the page. Status code:", response.status_code)
    

    ✅ Notes:

    • Replace "https://example.com" with the actual URL.
    • Adjust the tag and class names in soup.find_all() depending on how the website is structured (e.g., might be h1, h3, or another class).
    • Always respect a site's robots.txt and terms of service before scraping.

    Would you like a version that scrapes a real news/blog site like quotes.toscrape.com (a test site for web scraping)?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.