Created
January 14, 2021 23:15
-
-
Save jitsejan/8b50723bceccee732fa68cd212a59d42 to your computer and use it in GitHub Desktop.
Send automated mail from crawler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import ssl | |
import lxml.html | |
import requests | |
URL = "https://happiestbaby.co.uk/products/snoo-smart-bassinet" | |
resp = requests.get(URL) | |
tree = lxml.html.fromstring(resp.content) | |
price = tree.cssselect(".snoo-price-options")[0].text_content().strip() | |
port = 465 # For SSL | |
smtp_server = "smtp.gmail.com" | |
sender_email = "[email protected]" # Enter your address | |
receiver_email = "[email protected]" # Enter receiver address | |
password = "AapjeAapj3" | |
message = f"""\ | |
Subject: {price} | |
Sent from dev.jitsejan.com. Check your crontab -e! | |
""" | |
context = ssl.create_default_context() | |
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: | |
server.login(sender_email, password) | |
server.sendmail(sender_email, receiver_email, message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment