Created
March 20, 2021 13:05
-
-
Save LuisPalacios/9e9a6fc6b59f2de6bb4e722c769efe09 to your computer and use it in GitHub Desktop.
Prueba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Comprobar el precio de un producto en Amazon | |
''' | |
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | |
python3 get-pip.py | |
pip install virtualenv | |
virutalenv venv | |
Librerias para temas de Autenticción Web: | |
- BeautifulSoup | |
- Selenium | |
- Machanize | |
Chrome -> Alt-Cmd-i (Sección Elementos) | |
Abro amazon.es | |
Busco por ejemplo iphone12, entro en uno de ellos | |
Select Element Shift+Cmd+C | |
Título: <span id="productTitle" class="a-size-large product-title-word-break">Nuevo Apple iPhone 12 (128 GB) - Azul</span> | |
Precio: <span id="priceblock_ourprice" class="a-size-medium a-color-price priceBlockBuyingPriceString">930,00 €</span> | |
''' | |
# Web Scrapping. | |
import time # Gestión de campos fecha y tiempo. | |
import re # Regular expressions | |
import requests # Peticiones HTML (pip install requests) | |
from bs4 import BeautifulSoup # Librería navegar y parser de páginas web. (pip install bs4) | |
# https://www.crummy.com/software/BeautifulSoup/bs4/doc/ | |
# pip install html5lib | |
# pip install lxml | |
import smtplib # | |
# Let's Go !!! | |
url = "https://www.amazon.es/Nuevo-Apple-iPhone-12-128-GB/dp/B08L5S3XNM" | |
# Buscar en Google "mi user-agent" | |
header = { 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" } | |
def comprobar_precio(): | |
pagina = requests.get(url, headers=header) | |
sopa = BeautifulSoup(pagina.content, 'html.parser') | |
# print(pagina) | |
# print(sopa).prettify() | |
# Título: <span id="productTitle" class="a-size-large product-title-word-break">Nuevo Apple iPhone 12 (128 GB) - Azul</span> | |
# Precio: <span id="priceblock_ourprice" class="a-size-medium a-color-price priceBlockBuyingPriceString">930,00 €</span> | |
titulo = sopa.find(id='productTitle').get_text().strip() | |
precio = sopa.find(id='priceblock_ourprice').get_text().strip() | |
print("Título: ", titulo) | |
print("Precio: ", precio[:-5]) | |
comprobar_precio() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment