电商商品降价后自动发邮件通知
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
| import requests import smtplib import time from bs4 import BeautifulSoup
url = 'https://www.amazon.cn/dp/B07VZZS2PW/ref=sr_1_12?__mk_zh_CN=%E4%BA%9A%E9%A9%AC%E9%80%8A%E7%BD%91%E7%AB%99' \ '&keywords=ipad+air3&qid=1583638573&sr=8-12 '
headers = { "User-Agent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 ' 'Safari/537.36'}
def check_price(): page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text()
price = soup.find(id="priceblock_ourprice").get_text() converted_price = float(price[1:4]) if converted_price > 100: send_mail()
def send_mail(): server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() server.ehlo() server.login('@gmail.com', '') subject = 'Price fell down' body = 'Check the amazon link ' + url msg = f"Subject:{subject}\n\n{body}" server.sendmail('@gmail.com', '@163.com', msg) print('HEY EMAIL has been') server.quit()
while True: check_price() time.sleep(60 * 60 * 60)
|
-
Next Post
ss
-
Previous Post
快捷键