You are on page 1of 1

import requests

from bs4 import BeautifulSoup


import pandas as pd
import re

baseurl = 'https://www.emag.ro/'
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/51.0.2704.103 Safari/537.36'
}

for x in range(1,15):
r = requests.get(f'https://www.emag.ro/televizoare/p{x}/c')
soup = BeautifulSoup(r.content, 'lxml')

productlist = soup.find_all('div',class_='card-section-mid')
productlinks = []

for item in productlist:


for link in item.find_all('a', href=True):
productlinks.append(link['href'])

patern = '[\d]{1,2}[%]'
televizoare = []
for link in productlinks:
r = requests.get(link,headers=headers)
soup = BeautifulSoup(r.content,'lxml')
produs = soup.find('h1',class_='page-title').text.strip()
old_price = soup.find('s').text.strip()
new_price = soup.find('p',class_='product-new-price').text.strip()
discount1 = soup.find('span',class_="product-this-deal").text.strip()
discount = re.findall(patern,discount1)
print(produs,old_price,new_price,discount)
televizoare = {
'produs': produs,
'pret vechi': old_price,
'pret nou': new_price,
'reducere': discount
}

lista_televizoare.append(televizoare)

You might also like