In [1]:
import requests
from bs4 import BeautifulSoup

In [2]:
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 [3]:
html = requests.get(URL+search)

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

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


['R$ 138,43', 'R$ 82,68', 'R$ 157,45', 'R$ 126,04', 'R$ 163,84 - 168,60', 'R$ 185,10 - 222,97', 'R$ 8,91', 'R$ 246,01', 'R$ 157,35', 'R$ 17,42', 'R$ 237,47 - 242,60', 'R$ 14,84', 'R$ 31,48', 'R$ 156,21', 'R$ 216,51', 'R$ 5,83', 'R$ 3,45', 'R$ 149,58', 'R$ 121,82 - 190,83', 'R$ 32,42', 'R$ 4,39', 'R$ 8,98', 'R$ 146,30', 'R$ 17,08', 'R$ 34,16', 'R$ 53,55', 'R$ 154,97', 'R$ 106,82', 'R$ 174,09', 'R$ 40,76', 'R$ 113,52', 'R$ 27,73', 'R$ 23,18', 'R$ 21,60', 'R$ 323,33', 'R$ 210,92', 'R$ 6,50', 'R$ 3,69', 'R$ 77,02', 'R$ 131,46', 'R$ 2,35', 'R$ 60,91', 'R$ 2,85', 'R$ 34,16']

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 [ ]: