в общем вот код, когда сохраняю в json файл, проверяю и выходят только последние данные
import requests
from bs4 import BeautifulSoup
import json
url = "https://scrapingclub.com/exercise/list_basic/"
headers = {
....
}
response = requests.get(url=url, headers=headers)
soup = BeautifulSoup(response.text, "lxml")
data = soup.find("div", class_="row my-4")
catalog = []
for items in data:
cards_hrefs = data.find_all("div", class_="card-body")
for href in cards_hrefs:
href = "https://scrapingclub.com" + href.find("a").get("href")
catalog.append({
"link to the product": href
})
titles = data.find_all("div", class_="card-body")
for title in titles:
title = title.find("h4").text.strip()
catalog.append({
"title":title
})
prices = data.find_all("div", class_="card-body")
for price in prices:
price = price.find("h5").text.strip()
catalog.append({
"price":price
})
with open(f"data/catalog.json", "a", encoding="utf-8-sig") as file:
json.dump(catalog, file, indent=4, ensure_ascii=False)