FRIKIdelTO

Scrapping AliExpress con BeautifulSoup

Mar 1st, 2020 (edited)
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # SCRAPPING AliExpress
  3. # Esta página es oro puro: https://codebeautify.org/jsonviewer
  4. import requests
  5. import re
  6. import json
  7. from bs4 import BeautifulSoup
  8.  
  9. req = requests.get('https://es.aliexpress.com/item/4000055758113.html')
  10.  
  11. soup = BeautifulSoup(req.text, "html.parser")
  12. #print (soup)
  13. tag = soup.find('script', string=re.compile('window.runParams'))
  14. #print(tag)
  15. extr = re.search(r'window\.runParams = \{\s+data: (\{[\s\S]+\}\})[\s\S]+\}\;\n', tag.getText())
  16. conv = json.loads(extr.group(1))
  17. #print(extr.group(1))
  18.  
  19. nombre_producto = conv["pageModule"]["title"] # Descripción del artículo
  20. vendedor = conv['storeModule']['storeName'] # Nombre del vendedor
  21. n_categoria = len(conv['crossLinkModule']['breadCrumbPathList']) # Cuántas categorías hay
  22. categoria = conv['crossLinkModule']['breadCrumbPathList'][n_categoria-1]['name'] # Última categoría
  23. precio_anterior = conv['skuModule']['skuPriceList'][0]['skuVal']['skuAmount']['value'] # Precio anterior
  24. precio_actual = float(conv['skuModule']['skuPriceList'][0]['skuVal']['actSkuMultiCurrencyCalPrice']) # Precio actual
  25. likes = conv['actionModule']['itemWishedCount'] # Cuántos 'Me Gusta' tiene el artículo
  26. stock = conv['actionModule']['totalAvailQuantity'] # Cuántas unidades hay disponibles
  27. url_imagen = conv['imageModule']['imagePathList'][0] # URL de la imagen
  28. valoracion = float(conv['titleModule']['feedbackRating']['averageStar']) # Valoración de los clientes
  29.  
  30. print ("")
  31. print ("NOMBRE PRODUCTO...: " + nombre_producto)
  32. print ("")
  33. print ("VENDEDOR..........: " + vendedor)
  34. print ("")
  35. print ("CATEGORIA.........: " + categoria)
  36. print ("")
  37. print ("PRECIO ANTERIOR...: " + str(precio_anterior))
  38. print ("")
  39. print ("PRECIO ACTUAL.....: " + str(precio_actual))
  40. print ("")
  41. print ("LIKES.............: " + str(likes))
  42. print ("")
  43. print ("STOCK.............: " + str(stock))
  44. print ("")
  45. print ("URL IMAGEN........: " + url_imagen)
  46. print ("")
  47. if valoracion != 0:
  48.     print ("VALORACIÓN........: " + str(valoracion) + " de 5")
  49.     print ("")
Add Comment
Please, Sign In to add comment