Professional Documents
Culture Documents
Новий Текстовий документ
Новий Текстовий документ
Новий Текстовий документ
def get_iphone_models(url):
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
iphone_models = []
# Кольори
colors_list = []
colors_elem = product.find('ul', class_='goods-tile__colors-list')
if colors_elem:
color_items = colors_elem.find_all('li', class_='goods-tile__colors-
item')
for color_item in color_items:
style = color_item.find('span', class_='goods-tile__colors-
content')['style']
color = style.split(':')[-1].strip(';').strip()
colors_list.append(color)
else:
colors_list = ['Не вказано']
model['Колір'] = colors_list
model.update(screen_details)
iphone_models.append(model)
return iphone_models
def save_to_json(data):
with open('iphone_models.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
if __name__ == "__main__":
url = 'https://rozetka.com.ua/ua/mobile-phones/c80003/producer=apple/'
iphone_models = get_iphone_models(url)
save_to_json(iphone_models)