text_plain_output_1.png
from bs4 import BeautifulSoup

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import re

import requests

url = 'https://www.trendyol.com/cep-telefonu-x-c103498?pi=6?'
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 OPR/98.0.0.0'}
page = requests.get(url, headers=header)

soup = BeautifulSoup(page.content, 'html.parser')
product_cards = soup.find_all('div', class_='p-card-wrppr')
dataset = []
for card in product_cards:
    product_down_div = card.find('div', class_='product-down')
    product_name_div = product_down_div.find('div', class_='prdct-desc-cntnr-ttl-w two-line-text')
    product_name_span_1 = product_name_div.find('span', class_='prdct-desc-cntnr-ttl')
    product_name_span_2 = product_name_div.find('span', class_='prdct-desc-cntnr-name hasRatings')
    product_name_1 = product_name_span_1.text.strip() if product_name_span_1 else None
    product_name_2 = product_name_span_2.text.strip() if product_name_span_2 else None
    star_ratings_container = product_down_div.find('div', class_='ratings')
    filled_star_count = None
    if star_ratings_container:
        star_w_divs = star_ratings_container.find_all('div', class_='star-w')
        for star_w_div in star_w_divs:
            star_div = star_w_div.find('div', class_='full')
            if star_div and star_div.get('style'):
                width_match = re.search('width:\\s*([\\d.]+)%', star_div['style'])
                if width_match:
                    width = float(width_match.group(1))
                    if width > 0:
                        filled_star_count = round(width / 20)
    rating_count_span = product_down_div.find('span', class_='ratingCount')
    rating_count = int(rating_count_span.text.strip('()')) if rating_count_span else None
    price_promotion_container = product_down_div.find('div', class_='prc-box-dscntd')
    original_price_div = price_promotion_container.text.strip()
    product_data = {'Brand': product_name_1, 'Product': product_name_2, 'Filled Star Percentages': filled_star_count, 'Original Price': original_price_div, 'Rating Count': rating_count}
    dataset.append(product_data)
df = pd.DataFrame(dataset)
print(df)
df.to_csv('trendyol_data.csv')