-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
146 lines (113 loc) · 4.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import bs4
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
import time
import sys
import smtplib
from email.message import EmailMessage
from datetime import datetime
import sys
from termcolor import colored, cprint
def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
user = "[email protected]"
msg['from'] = user
password = "ispyfdqsaoxfxdcp"
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
server.send_message(msg)
server.quit()
def LDLC():
ua = UserAgent()
opts = Options()
opts.add_argument("user-agent=" + ua.random)
opts.add_argument('headless')
driver = webdriver.Chrome(options=opts)
driver.get("https://www.ldlc.com/es-es/informatica/perifericos-pc/gafas-de-realidad-virtual/c7460/")
html = driver.page_source
soup = bs4.BeautifulSoup(html, "html.parser")
item_in_store = soup.find_all("div", {"class": "modal-stock-web pointer stock stock-9"})
in_stock = []
for product in item_in_store:
if "Agotado" in str(product):
in_stock.append('Hay Stock')
if len(in_stock) < 2:
email_alert("LDLC: Ha vuelto el stock", "¡Buenas! Ya puedes entrar en la página. ¡Date prisa!","[email protected]")
print("email enviado, STOCK EN LDLC")
return("LDLC: EN STOCK")
return("LDLC: SIN STOCK")
def ECI():
ua = UserAgent()
opts = Options()
opts.add_argument("user-agent="+ua.random)
opts.add_argument('headless')
driver = webdriver.Chrome(options=opts)
driver.get("https://www.elcorteingles.es/videojuegos/ps5/consolas/")
html = driver.page_source
soup = bs4.BeautifulSoup(html,"html.parser")
item_in_store = soup.find_all("span", {"class":"tooltip"})
in_stock = []
for product in item_in_store:
if("Añadir a la cesta" in product.text):
in_stock.append(product.find_parent("a")["href"])
#email_alert("Importante, ha vuelto el stock", "¡Buenas!Ya puedes entrar en la página. ¡Date prisa!", "[email protected]")
base_url = "https://elcorteingles.es"
if len(in_stock)>0:
email_alert("Importante, ha vuelto el stock", "¡Buenas! Ya puedes entrar en la página. ¡Date prisa!", "[email protected]")
print("email enviado, STOCK EN EL CORTE INGLES")
return ('EL CORTE INGLES: EN STOCK')
return ('EL CORTE INGLÉS: SIN STOCK')
for url in in_stock:
url = base_url + url
print(url)
def xtralife1():
ua = UserAgent()
opts = Options()
opts.add_argument("user-agent=" + ua.random)
opts.add_argument('headless')
driver = webdriver.Chrome(options=opts)
driver.get("https://www.xtralife.com/producto/ps5-starter-pack-17-ps5-starter-pack-17/69718")
html = driver.page_source
soup = bs4.BeautifulSoup(html, "html.parser")
item_in_store = soup.find_all("p", {"class": "actionText colorWhite fontBold fontNormal"})
if "Reservar ahora" in str(item_in_store):
email_alert("XTRALIFE: RESERVAR PACK 17", "¡Buenas! Ya puedes entrar en la página. ¡Date prisa!","[email protected]")
print("email enviado, STOCK EN XTRALIFE PACK 17")
return("XTRALIFE PACK 17: EN STOCK")
return("XTRALIFE PACK 17: SIN STOCK")
def xtralife2():
ua = UserAgent()
opts = Options()
opts.add_argument("user-agent=" + ua.random)
opts.add_argument('headless')
driver = webdriver.Chrome(options=opts)
driver.get("https://www.xtralife.com/producto/ps5-starter-pack-21-ps5-starter-pack-21/69722")
html = driver.page_source
soup = bs4.BeautifulSoup(html, "html.parser")
item_in_store = soup.find_all("p", {"class": "actionText colorWhite fontBold fontNormal"})
if "Reservar ahora" in str(item_in_store):
email_alert("XTRALIFE: RESERVAR PACK 21", "¡Buenas! Ya puedes entrar en la página. ¡Date prisa!","[email protected]")
print("email enviado, STOCK EN XTRALIFE PACK 21")
return("XTRALIFE PACK 21: EN STOCK")
return ("XTRALIFE PACK 21: SIN STOCK")
while True:
driver = webdriver.Chrome()
driver.get("https://www.elcorteingles.es/videojuegos/ps5/consolas/")
html = driver.page_source
soup = bs4.BeautifulSoup(html,"html.parser")
item_in_store = soup.find_all("span", {"class":"tooltip"})
in_stock = []
for product in item_in_store:
if("Añadir a la cesta" in product.text):
in_stock.append(product.find_parent("a")["href"])
base_url = "https://elcorteingles.es"
for url in in_stock:
url = base_url + url
print(url)
time.sleep(10)
print("Scraping finished")