当前位置 : 主页 > 编程语言 > python >

python爬虫爬取下厨房食谱,周末聚餐真的停不下来

来源:互联网 收集:自由互联 发布时间:2022-06-15
下厨房,专为不会做菜的男生提供烹饪教程。 结果: 代码: import requests import smtplib from bs4 import BeautifulSoup from email . mime . text import MIMEText from email . header import Header account = "你的QQ号@


下厨房,专为不会做菜的男生提供烹饪教程。

结果:

python爬虫爬取下厨房食谱,周末聚餐真的停不下来_ide

python爬虫爬取下厨房食谱,周末聚餐真的停不下来_邮件发送_02

代码:

import requests
import smtplib
from bs4 import BeautifulSoup
from email.mime.text import MIMEText
from email.header import Header

account = "你的QQ号@qq.com"
password = "POP3/SMTP服务的授权码"#不会弄?见文末教你玩。
receiver = "你的QQ号@qq.com"


def recipe_spider():
res_foods = requests.get('http://www.xiachufang.com/explore/')
bs_foods = BeautifulSoup(res_foods.text, 'html.parser')
list_foods = bs_foods.find_all('div', class_='info pure-u')
list_all = ''
num = 0
for food in list_foods:
num = num + 1
tag_a = food.find('a')
name = tag_a.text.strip()
url = 'http://www.xiachufang.com' + tag_a['href']
tag_p = food.find('p', class_='ing ellipsis')
ingredients = tag_p.text.strip()
food_info = '''
序号: %s
菜名: %s
链接: %s
原料: %s
''' % (num, name, url, ingredients)
list_all = list_all + food_info
print(list_all)
global a
a = list_all
return (list_all)

recipe_spider()


def send_email(a):
mailhost = 'smtp.qq.com'
qqmail = smtplib.SMTP()
qqmail.connect(mailhost, 25)
qqmail.login("1981791922@qq.com", "ywo-ixfoe-rmggad")
content = '亲爱的,本周的热门菜谱如下' + a
message = MIMEText(content, 'plain', 'utf-8')
subject = '周末吃个啥'
message['Subject'] = Header(subject, 'utf-8')
try:
qqmail.sendmail(account, receiver, message.as_string())
print('邮件发送成功')
except:
print('邮件发送失败')
qqmail.quit()


def job():
print('开始一次任务')
list_all = recipe_spider()
send_email(list_all)
print('任务完成')
if __name__ == "__main__":
job()

过程:

授权码怎么获取呢?

进入:https://mail.qq.com/

设置—>账户—>图片操作

python爬虫爬取下厨房食谱,周末聚餐真的停不下来_python_03

这样,你也可以获取一份下厨房食谱了,天下少有你烹饪不出来的美味。

关注我,为思考点赞!



【本文转自:日本cn2服务器 http://www.558idc.com/jap.html提供,感恩】
上一篇:Django 学习笔记(七)
下一篇:没有了
网友评论