当前位置:网站首页>用代码收集每天热点内容信息,并发送到自己的邮箱
用代码收集每天热点内容信息,并发送到自己的邮箱
2022-07-30 06:33:00 【松鼠爱吃饼干】
目录
前言
本篇文章内容主要为如何用代码,把你想要的内容,以邮件的形式发送出去
内容可以自己完善,还可以设置一个定时发送,或者开机启动自动运行代码
代理注册与使用
注册账号并登录

生成api

将自己电脑加入白名单
http://api.tianqiip.com/white/add?key=xxx&brand=2&sign=xxx&ip=输入自己电脑的ip地址
1. win+R 输入cmd

2. 回车在弹出的窗口里面输入 ipconfig
当前ipv4就是自己的ip地址

3. 添加白名单(输入ip之后直接访问即可)
http://api.tianqiip.com/white/add?key=xxx&brand=2&sign=xxx&ip=输入自己电脑的ip地址
备注: 每个人的地址不一样需要自己在提取ip页面查找

代码实现
邮箱发送
def sendEmail(title, content, received_mail):
# 邮箱属性配置
# 邮箱服务端
mailserver = 'smtp.qq.com'
# 发件人-此邮箱是我随便写的
userName_SendMail = '***@qq.com'
# 邮箱发件授权码-为发件人邮箱根据第四步生成的授权码
userName_AuthCode = '******'
# 定义邮件的接收者-我随便写的,若收件人较多,可用列表表示
received_mail = [received_mail]
# 发送一封简单的邮件,处理邮件内容
# content = content
# 纯文本形式的邮件内容的定义,通过MIMEText进行操作,plain为默认的文本的展示形式
email = MIMEText(content, 'plain', 'utf-8')
email['Subject'] = title # 定义邮件主题
email['From'] = userName_SendMail # 发件人
email['To'] = ','.join(received_mail) # 收件人(可以添加多个,若只有一个收件人,可直接写邮箱号)
# 发送邮件
# QQ邮箱的端口号是465,其他邮箱的端口号可自行百度,非QQ邮箱,一般使用SMTP即可,不需要有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('邮件发送成功')
新闻内容获取
首先,找到你想要的数据在哪
打开开发者工具,点一下放大镜,搜索关键词

然后在Headers里找到数据所在的url链接

导入所需模块,以及写好的代码
import requests
import re
from SendEmail import sendEmail
获取想要的新闻信息
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("今日百度热搜", content, '****@qq.com')
哔站视频号个人主页:松鼠爱吃饼干
200+ Python案例讲解
边栏推荐
- 【COCI 2020/2021 Round #2 D】Magneti (DP)
- sql concat()函数
- LSF提交作业命令--bsub
- IDEA搜索插件无结果一直转圈圈的解决办法
- this与super
- golang: Gorm configures Mysql multiple data sources
- 入选“十大硬核科技”,详解可信密态计算(TECC)技术点
- DNS domain name resolution services
- K-Net:Towards Unified Image Segmentation,基于动态内核的通用分割网络,(NMS-free and Box-free),从语义/实例分割到全景分割。
- A magical no main method of code
猜你喜欢

How does Redis prevent oversold and inventory deduction operations?

ETL为什么经常变成ELT甚至LET?

Go 结合Gin导出Mysql数据到Excel表格

你好,我的新名字叫 “铜锁 / Tongsuo”

uniapp中canvas与v-if更“配”

Universal js time date format conversion

物联网网关该怎么选

K-Net:Towards Unified Image Segmentation,基于动态内核的通用分割网络,(NMS-free and Box-free),从语义/实例分割到全景分割。

DP5340 domestic replacement for CM5340 stereo audio A/D converter chip

golang : Zap日志整合
随机推荐
go : 使用 grom 删除数据库数据
bean的生命周期
专访蚂蚁:这群技术排头兵,如何做好底层开发这件事?| 卓越技术团队访谈录
go : 使用gorm查询记录
Burpsuite几种爆破方式
go : go-redis set operations
Go combines Gin to export Mysql data to Excel table
ArrayList
Distributed lock development
Get all interface paths and names in the controller
Go 结合Gin导出Mysql数据到Excel表格
Go: use gorm query record
Input method for programmers
assert
Fix datagrip connection sqlserver error: [08S01] The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.
go : use gorm to modify data
mysql URL链接
MySQL off-topic [ORM thought analysis]
BGP:边界网关路由协议 无类别的路径矢量EGP协议
MySQL基础篇【命名规范】