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