Sunday, February 9, 2020

Read website and send mail in Python

import requests
from bs4 import BeautifulSoup
import smtplib
URL = 'https://hulagabal.blogspot.com/'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="header-inner").get_text()
print(title.strip())
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('email@gmail.com', '<your-password>')
subject = title.strip()
body = title.strip()
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
'Please check',
'to-email@gmail.com',
msg
)
print('Hey Email has been sent!')
server.quit()
view raw myalerts.py hosted with ❤ by GitHub