python 今天在AFI给我发电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 今天在AFI给我发电子邮件相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python3.6

import requests

from bs4 import BeautifulSoup

#Variables
afi_website_url  = 'http://www.afi.com/silver/films/calendar.aspx'
mail_sender_service = 'https://api.mailgun.net/v3/sandboxec1e86e70f9641de94f341d840592733.mailgun.org/messages'
mail_sender_service_key = 'key-XXXXXXXXXXXXXXX'
sender = 'Jason <test@test.com>'
recipients = ['test@test.com',]

#Go get the web page
response = requests.get(afi_website_url)

#text comes back ...turn it back into HTML
soup = BeautifulSoup(response.text, 'lxml')

#Get the movies in the today's div
movies = soup.select('.today a')

#The email I'm going to send
email = ''

#This div only contains links to the movies, but I want their descriptions, so loop over each movie
for movie in movies:
	#...and get it's URL
	url = movie['href'].replace('/silver/films/', '')
	#...now go get it
	response = requests.get(url)
	#text comes back ...turn it back into HTML
	soup = BeautifulSoup(response.text, 'lxml')
	#Pick out it's title and description and add it to our email
	title = soup.select('.film-info .boxout-title')[0]
	description = soup.select('.film-info .boxout-blurb')[0]
	email += "<a href='{}'>{}</a>{}<br/>".format(url, title, description)

#Now that the email is ready, send it!
response = requests.post(
	mail_sender_service,
	auth=('api', mail_sender_service_key),
	data={
		'from': sender,
		'to': recipients,
		'subject': 'Today\'s movies at the AFI are...',
		'html': email
	}
)

print('All Done!')

以上是关于python 今天在AFI给我发电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

请给我发邮件,不要发微信

有没有啥可以查IP的软件 给我发一个好么

谁帮我看下Linux系统给我发的邮件。有没有重要的错误。

大表哥微信给我发了很多资源!结果被和谐了!Python秒存不被和谐

每日一书|建大数据平台太难了,给我发个工程原型吧

给我发代码!马斯克强制要求推特员工写周报,还招来黑客大佬改程序