-
Notifications
You must be signed in to change notification settings - Fork 16
/
web_scrapper.py
60 lines (31 loc) · 1.37 KB
/
web_scrapper.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
from bs4 import BeautifulSoup
import requests
import smtplib
import email.message
URL = "https://www.brasiltronic.com.br/camera-sony-alpha-a6400-com-lente-16-50mm-f-35-56-lente-oss-p1324121"
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"}
site = requests.get(URL, headers=headers)
soup = BeautifulSoup(site.content, 'html.parser')
title = soup.find('h1', class_ = 'name').get_text()
price = soup.find('strong', class_='sale-price').get_text().strip()
num_price = price[3:8]
num_price = num_price.replace('.','')
num_price = float(num_price)
def send_email():
email_content = """
https://www.brasiltronic.com.br/camera-sony-alpha-a6400-com-lente-16-50mm-f-35-56-lente-oss-p1324121
"""
msg = email.message.Message()
msg['Subject'] = 'Preço Camera Sony A6400 BAIXOU!!!!'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
password = 'beautifulsoup'
msg.add_header('Content-Type', 'text/html')
msg.set_payload(email_content)
s = smtplib.SMTP('smtp.gmail.com: 587')
s.starttls()
s.login(msg['From'], password)
s.sendmail(msg['From'], [msg['To']], msg.as_string())
print("Sucesso ao enviar email")
if (num_price < 8000):
send_email()