0% found this document useful (0 votes)
7 views2 pages

Scraping Quotes to SQLite Database

The document outlines a web scraping program that extracts quotes from a specified website using the BeautifulSoup library and stores them in an SQLite database. It includes functions for scraping the quotes and for creating a database table to store them. The program executes these functions and confirms successful data storage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Scraping Quotes to SQLite Database

The document outlines a web scraping program that extracts quotes from a specified website using the BeautifulSoup library and stores them in an SQLite database. It includes functions for scraping the quotes and for creating a database table to store them. The program executes these functions and confirms successful data storage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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:

You might also like