Aim :
Web Scraping : Create a program that uses a web scraping library to extract data from a
website and then stores it in a database.
Code:
import requests
from bs4 import BeautifulSoup
import sqlite3
def scrape_quotes():
url = "[Link]
response = [Link](url)
soup = BeautifulSoup([Link], '[Link]')
quotes = []
for quote in [Link]('.text'):
[Link](quote.get_text())
return quotes
def store_in_database(quotes):
conn = [Link]('[Link]')
cursor = [Link]()
[Link]('''
CREATE TABLE IF NOT EXISTS quotes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
quote TEXT
)
''')
for quote in quotes:
[Link]('INSERT INTO quotes (quote) VALUES (?)', (quote,))
[Link]()
[Link]()
if __name__ == "__main__":
quotes_data = scrape_quotes()
if quotes_data:
store_in_database(quotes_data)
print("Quotes successfully scraped and stored in the database.")
else:
print("Error in scraping quotes.")
Output: