Skip to content

Instantly share code, notes, and snippets.

@Laurent-Andrieu
Created February 28, 2021 15:46
Show Gist options
  • Save Laurent-Andrieu/8a96c91fc128b4aa6074e32fd1c107a2 to your computer and use it in GitHub Desktop.
Save Laurent-Andrieu/8a96c91fc128b4aa6074e32fd1c107a2 to your computer and use it in GitHub Desktop.
Scrapper + E-Mail: article site converse
from bs4 import BeautifulSoup
import urllib.request
import urllib.error
import smtplib
WANTED_SIZE = [44.5, 45, 46.5]
URL = "https://www.converse.com/fr/regular/marble-chuck-70/167374C_120.html?lang=fr_FR&csid" \
"=PSH_PRF_CNV_WE_FR_FR_20191101_FPMX_GO-SH-FR-CSS-Sale&gclid=CjwKCAiAm" \
"-2BBhANEiwAe7eyFK2DhgMrYsEfsJibzwSpxrXTMRlSYlCi9FARKhLV9rtSfgKtQ8XY-xoCyAYQAvD_BwE&gclsrc=aw.ds" \
"#2_9686277730_PLA_X_X_Google_GO-SH-FR-CSS-Sale-Chuck70_X_aud-1177328929332:pla" \
"-1030466621673_99584272717_428227817503_m "
user = "@gmail.com"
password = ""
def test_connexion():
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
ack = int(list(server.ehlo())[0])
server.close()
return ack
except Exception as conn_failure:
print(f"Connexion failure:{conn_failure}")
return None
def send(usr, passw, data):
content = f"""
From: scraper.py
Subject: Converse Marble Ckuck 70
URL: {URL}
Taille(s) recherchee(s): {WANTED_SIZE}
Taille(s) trouvee(s): {data}
"""
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login(usr, passw)
server.sendmail(usr, usr, content)
server.close()
print(f"Sent:\n{content}")
except Exception as err:
raise err
def process(html):
sizes_list = []
found = []
options = html.find('div', attrs={'class': 'variations__container variations__container--dropdown toggle-box '
'toggle-box--single set--themeable'})
if options:
options_ouput = str(options.find_all('option')).split("</option>")
try:
for option in options_ouput:
sizes = option.split('\n')[1].split('\n')[0]
sizes_list.append(sizes)
except IndexError:
pass
del sizes_list[0]
for size in sizes_list:
size = float(size)
if size in WANTED_SIZE:
found.append(size)
return found
while not test_connexion() == 250:
test_connexion()
else:
try:
page = urllib.request.urlopen(URL)
html_file = BeautifulSoup(page, 'html.parser')
data = process(html_file)
send(user, password, data)
except urllib.error.URLError as querry_error:
print(querry_error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment