-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto.py
More file actions
42 lines (33 loc) · 1.29 KB
/
Copy pathauto.py
File metadata and controls
42 lines (33 loc) · 1.29 KB
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
import requests
from bs4 import BeautifulSoup
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Set your email credentials
email = "your_email@example.com"
password = "your_password"
# Set the recipient email address (for testing purposes, you can use your own email)
recipient_email = "recipient_email@example.com"
# Download the web page using requests
url = "https://example.com"
response = requests.get(url)
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, "html.parser")
# Extract specific information using BeautifulSoup (modify as needed)
info = soup.find("div", {"class": "some_class"}).get_text()
# Compose the email message
subject = "Extracted Information"
body = f"Here's the extracted information from {url}:\n\n{info}"
msg = MIMEMultipart()
msg["From"] = email
msg["To"] = recipient_email
msg["Subject"] = subject
msg.attach(MIMEText(body, "plain"))
# Send the email using your email account credentials
try:
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(email, password)
server.sendmail(email, recipient_email, msg.as_string())
print(f"Email sent to {recipient_email}")
except Exception as e:
print(f"Error occurred: {e}")