Untitled
unknown
plain_text
3 years ago
1.5 kB
14
Indexable
import requests
from bs4 import BeautifulSoup
import csv
# Send a GET request to the URL
url = 'https://www.alkitab.tn/list-105801/new-english-books/'
response = requests.get(url)
# Parse the HTML content using Beautiful Soup
soup = BeautifulSoup(response.content, 'html.parser')
# Find all div elements with class 'meta_produit col-md-10 col-xs-8 no-padding'
product_divs = soup.find_all('div', class_='meta_produit col-md-10 col-xs-8 no-padding')
# Create a CSV file to store the scraped data
with open('scraped_data.csv', 'w', newline='', encoding='utf-8') as csv_file:
csv_writer = csv.writer(csv_file)
# Write the headers to the CSV file
csv_writer.writerow(['ISBN', 'Bookname', 'Price', 'Author', 'Editor'])
# Loop through each product div and extract the relevant data
for product_div in product_divs:
# Extract the ISBN, Bookname, Price, Author, and Editor from the relevant div elements
isbn = product_div.find('div', class_='hidden-xs').text.strip()
bookname = product_div.find('h4', class_='livre_titre').text.strip()
price = product_div.find('div', class_='item_prix ml-01 table_prix_livraison paper ').text.strip()
author = product_div.find('h6', class_='livre_auteur').text.strip()
editor = product_div.find('div', class_='editeur').text.strip()
# Write the extracted data to the CSV file
csv_writer.writerow([isbn, bookname, price, author, editor])
Editor is loading...