Scraping of Quotes to Scrape in Python with Beautiful Soup


Quotes to Scrape Webpage.

Exhibit 25.32 Quotes to Scrape webpage.

The Quotes to Scrape Webpage, from Zyte’s web scraping sandbox, is a platform which used is by educators for web scraping tutorials and exercises. As shown in Exhibit 25.32 the site lists quotes from famous people.

Exhibit 25.33 demonstrates the scraping of the quotes, which appear within span elements identified by attribute class = ‘text’, with the Beautiful Soup Python library.

Scraping the “Quotes to Scrape” Webpage
import requests
from bs4 import BeautifulSoup

# (1) Send Request
url = "http://quotes.toscrape.com/page/1/"
response = requests.get(url)

# (2) Parse the HTML
soup = BeautifulSoup(response.text, "html.parser")

# (3) Navigate the Parse Tree: To find all quotes on the page
quotes = soup.find_all("span", class_="text")

# (4) Extract and Print the Quotes
for quote in quotes:
    print(quote.text)
“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”
“It is our choices, Harry, that show what we truly are, far more than our abilities.”
“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”
“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”
“Try not to become a man of success. Rather become a man of value.”
“It is better to be hated for what you are than to be loved for what you are not.”
“I have not failed. I've just found 10,000 ways that won't work.”
“A woman is like a tea bag; you never know how strong it is until it's in hot water.”
“A day without sunshine is like, you know, night.”

Exhibit 25.33 Scraping the Quotes to Scrape Webpage. Jupyter notebook.


Previous     Next

Use the Search Bar to find content on MarketingMind.