-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
47 lines (36 loc) · 1.14 KB
/
scraper.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
import requests
from bs4 import BeautifulSoup
import smtplib
import time
URL = 'https://amzn.to/3jV41Tc'
headers = {"User-Agent": 'Mozilla/5.0 (X11; Ubuntu;'
'Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0'}
def check_price():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'lxml')
title = soup.find(id="productTitle").get_text()
price = soup.find(id="priceblock_ourprice").get_text()
converted_price = float(price[0:3])
print(title.strip() + ': ')
print(converted_price)
if(converted_price < 400):
send_mail()
def send_mail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]', 'hbilikxwpkrofbej')
subject = 'Amazon Price Tracker App : Your item price fell down !'
body = 'Check it out here :\n' + URL
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
msg
)
print('AN EMAIL HAS BEEN SENT!')
server.quit()
while(True):
check_price()
time.sleep(86400)