Hi ππ
In this post i aill share with you how to Scrape quotes using Python.
I will to Scrape quotes from
https://quotes.toscrape.com/page/1/
step 1
Select html elements
Get quote class name
Get author name
from bs4 import BeautifulSoup
import requests
url = 'https://quotes.toscrape.com/page'
def scrape(url, page_num):
url = f'{url}/{page_num}'
res = requests.get(url)
html = BeautifulSoup(res.content, 'html.parser')
quotes = []
authors = []
for quote in html.find_all('span', class_ = 'text'):
quotes.append(quote.text)
for author in html.find_all('small', class_ = 'author'):
authors.append(author.text)
for i, quote in enumerate(quotes):
f = open('quotes.txt', 'a+', errors = 'ignore')
f.write(f'{quote} ## {authors[i]}\n')
f.close()
for i in range(20):
scrape(url, i)
Now we're done π€
Don't forget to like and follow π
Support me on PayPal π€
https://www.paypal.com/paypalme/amr396