程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to collect daily hot content information with Python code and send it to your mailbox?

編輯:Python

Hey, everyone, good duck ! I'm a panda

Today I want to bring you a fun python Small cases ~

Don't talk much , Let's start ~


what are you having? python I won't answer the related error report 、 Or source code information / Module installation / Women's clothing bosses are proficient in skills You can come here :(https://jq.qq.com/?_wv=1027&k=2Q3YTfym) perhaps +V:python10010 Ask me

Agent registration and use

Sign up for an account and log in

Generate api

Add your computer to the white list

http://api.tianqiip.com/white/add?key=xxx&brand=2&sign=xxx&ip= Enter your computer's ip Address

1. win+R Input cmd


2. Enter enter in the pop-up window ipconfig

At present ipv4 Just your own ip Address

3. Add whitelist ( Input ip Then visit directly )

http://api.tianqiip.com/white/add?key=xxx&brand=2&sign=xxx&ip= Enter your computer's ip Address
remarks : Everyone's address is different, and you need to extract it yourself ip Page search

Code implementation

E-mail

def sendEmail(title, content, received_mail):
# Mailbox property configuration 
# Mailbox server 
mailserver = 'smtp.qq.com'
# Sender - I wrote this email casually 
userName_SendMail = '***@qq.com'
# Email authorization code - The authorization code generated according to step 4 for the sender's mailbox 
userName_AuthCode = '******'
# Define the recipient of the message - I wrote it casually , If there are many recipients , A list can be used to represent 
received_mail = [received_mail]
# Send a simple email , Process mail content 
# content = content
# Definition of mail content in plain text , adopt MIMEText To operate ,plain It is the default display form of text 
email = MIMEText(content, 'plain', 'utf-8')
email['Subject'] = title # Define email subject 
email['From'] = userName_SendMail # Sender 
email['To'] = ','.join(received_mail) # The recipient ( Multiple can be added , If there is only one recipient , You can write the email number directly )
# Send E-mail 
# QQ The port number of the mailbox is 465, The port numbers of other mailboxes can be determined by themselves , Not QQ mailbox , In general use SMTP that will do , There is no need for SSL
smtp = smtplib.SMTP_SSL(mailserver, port=465)
smtp.login(userName_SendMail, userName_AuthCode)
smtp.sendmail(userName_SendMail, ','.join(received_mail), email.as_string())
smtp.quit()
print(' Mail sent successfully ')

News content acquisition

First , Find out where the data you want is
Open developer tools , Click the magnifying glass , Search keywords

And then in Headers Find the data in url link

Import the required modules , And the written code

import requests
import re
from SendEmail import sendEmail

Get the news information you want

url = 'https://top.baidu.com/board?tab=realtime&sa=fyb_realtime_31065'
response = requests.get(url)
content = re.findall('<!--s-data:(.*?)-->', response.text)[0]
sendEmail(" Today, baidu Hot search ", content, '****@qq.com')

Today's article is like this , I hope it can be helpful to you who are learning by yourself ~

I'm a panda , See you in the next article (*◡‿◡)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved