520表白神器-教你用微信每天给TA说晚安
又是一年虐狗日,有男票或女票的,礼物准备好没?
今天大家准备了一份520专属告白文案,可以用在恋情继续的告白上、也可以用在脱单告白上哦!
拿去吧,不用谢,谁让你是我的小可爱呢!
此程序结合数据抓取 + 微信自动发消息 + 定时任务,实现一个能每天自动定时给你心爱的 ta 发送:
每天发送的消息格式如下:
message = """
亲爱的{}:
早上好,今天是你和 Koc 相恋的第 {} 天~
今天他想对你说的话是:
{}
最后也是最重要的!
""".format("你的好友名称", str(inLoveDays), love_word)
这里需要填写的第一个字段是 ta 的称呼,inLoveDays 为你们相识相恋的天数。
love_word 是每天为 ta 精心准备情话内容,当然如果你的文笔好也可以自己写。
当然最后也是最重要的!每天不尽相同的「我爱你」图片!
今天呢, 我们先来第一步,
此函数通过 requests + xpath 来抓取情话网站的资源,并存入到当前目录下的「love_word.txt」文件。
import re
from lxml import etree
import requests
def crawl_Love_words():
print("正在抓取情话...")
url = "http://www.duanmeiwen.com/yulu/aiqing/8174.html"
html = requests.get(url).content
Selector = etree.HTML(html)
love_words_xpath_str = "//div[@class='content']/p/text()"
love_words = Selector.xpath(love_words_xpath_str)
for i in love_words:
word = i.strip("\n\t").strip()
with open('love.txt', "a") as file:
file.write(word + "\n")
print("情话抓取完成")
crawl_Love_words()