Web scraping: Extract title and body text from a URL

This technical problem involves writing a Python script to scrape the title and body text from a given URL.

Problem

Given a URL, write a Python script to scrape the title and body text of the webpage.
Example input:
http://example.com
Example output:
Title: Example Domain
Body: This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.
More information...

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
import requests
from bs4 import BeautifulSoup

url = 'http://example.com'

r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')

print('Title:', soup.title.string)
print('Body:', soup.p.string)

A.I. Evaluation of the Solution

The candidate's solution correctly scrapes the title and body text from the given URL. The solution is clear and concise.

Evaluated at: 2022-11-15 00:15:47