Automate Weather Forecast Emails with Python: Scrape, Process, Send

This guide shows how to use Python’s BeautifulSoup to scrape real‑time weather data from Sohu Weather, format the information, and automatically email the forecast to any address, with examples for Sohu, 163, and other mail servers, plus PM2.5 standards.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Automate Weather Forecast Emails with Python: Scrape, Process, Send

Overview

Using Python and BeautifulSoup, we scrape real‑time weather information from Sohu Weather, including city, weather condition, temperature, air quality, and PM2.5 value.

Scraping the Data

The get_weather function retrieves the required fields using BeautifulSoup selectors. The code (shown in the image below) demonstrates string handling, formatting, and a lambda expression.

Sending the Email

After obtaining the weather data, the send_email function composes an email and sends it via SMTP. By providing the sender’s address, password, and SMTP server, the script can automatically deliver the forecast to a list of recipients.

Result Screenshots

The email arrives in the inbox with the same weather details that were scraped, as shown in the screenshots for Sohu Mail and 163 Mail.

Email Server Settings

Common SMTP servers include:

QQ Mail: smtp.qq.com

126 Mail: smtp.126.com

163 Mail: smtp.163.com

Sina Mail: smtp.sina.com.cn

Sohu Mail: smtp.sohu.com

Yahoo Mail: smtp.mail.yahoo.com

Gmail: smtp.gmail.com

PM2.5 Reference Values

Air‑quality standards for 24‑hour PM2.5 averages are:

Excellent: ≤35 µg/m³

Good: 35–75 µg/m³

Light pollution: 75–115 µg/m³

Moderate pollution: 115–150 µg/m³

Heavy pollution: 150–250 µg/m³

Severe pollution: ≥250 µg/m³

For Dalian, the scraped PM2.5 value is 110 µg/m³, indicating light pollution.

By combining web‑scraping with automated email delivery, you can set up a daily weather‑forecast notification system.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonSMTPemail automationWeather Data
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.