aliexpress



In [24]:
import requests
from bs4 import BeautifulSoup

In [39]:
URL = 'https://pt.aliexpress.com/wholesale?catId=0&initiative_id=&SearchText='
XPATH = '/html/body/p[1]/strong'
TARGET = '<span class="value" itemprop="price">R$ 79,67</span>'
search = 'raspberry pi 3'

In [40]:
html = requests.get(URL+search)

In [41]:
bsObj = BeautifulSoup(html.text, "html.parser")
nameList = bsObj.findAll("span", {"class": "value", "itemprop": "price"})

In [42]:
lista = [row.getText() for row in nameList]
print (lista)


['R$ 121,49 - 190,31', 'R$ 32,36', 'R$ 173,61', 'R$ 17,03', 'R$ 157,01', 'R$ 29,82', 'R$ 174,11', 'R$ 138,05', 'R$ 140,22', 'R$ 5,82', 'R$ 163,39 - 168,13', 'R$ 188,84 - 193,85', 'R$ 8,62', 'R$ 210,34', 'R$ 78,11', 'R$ 3,44', 'R$ 128,56', 'R$ 3,74', 'R$ 2,34', 'R$ 17,37', 'R$ 130,20', 'R$ 8,65', 'R$ 150,24 - 227,04', 'R$ 2,84', 'R$ 128,56 - 148,60', 'R$ 6,15', 'R$ 128,76', 'R$ 76,81', 'R$ 156,95', 'R$ 215,92', 'R$ 128,56', 'R$ 10,32', 'R$ 149,17', 'R$ 13,90', 'R$ 19,21', 'R$ 232,15', 'R$ 32,33', 'R$ 6,02', 'R$ 49,76', 'R$ 138,21', 'R$ 131,10', 'R$ 27,65', 'R$ 12,26', 'R$ 128,56 - 148,60']

In [43]:
def extrai_valor(texto):
    pos_real = texto.index('R$') + 3
    pos_hifen = texto.find('-')
    if pos_hifen == -1:
        pos_hifen = len(texto)
    texto = texto[pos_real:pos_hifen]
    texto = texto.replace(',', '.')
    return float(texto)

lista_float = []
soma = 0
for item in lista:
    valor = extrai_valor(item)
    lista_float.append(valor)
    soma += valor
print('Média:', soma/len(lista_float))
print('Lista de preços: ', lista_float)


Média: 88.14886363636366
Lista de preços:  [121.49, 32.36, 173.61, 17.03, 157.01, 29.82, 174.11, 138.05, 140.22, 5.82, 163.39, 188.84, 8.62, 210.34, 78.11, 3.44, 128.56, 3.74, 2.34, 17.37, 130.2, 8.65, 150.24, 2.84, 128.56, 6.15, 128.76, 76.81, 156.95, 215.92, 128.56, 10.32, 149.17, 13.9, 19.21, 232.15, 32.33, 6.02, 49.76, 138.21, 131.1, 27.65, 12.26, 128.56]

In [ ]:


In [ ]: