碎碎念
掐指一算,混loc的日子应该也快一年了,刚开始还几乎每天都上论坛上翻翻帖子,可后来到现在越来越少上了,但也还会隔一段时间猛刷上个把小时,今天闲来无事写了个小爬虫用来每日推送loc的热帖。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/env python3 # coding = 'utf-8' """ @Time : 2020/3/26-18:51 @Author : sharp @FileName: hostloc_hot.py @Software: PyCharm @Blog :https://www.sharpgan.com/ """ import time import smtplib import requests from bs4 import BeautifulSoup from email.mime.text import MIMEText HOST = 'smtp.qq.com' PORT = 587 SENDER = '@qq.com' RECEIVER = '@qq.com' PWD = '' def mail_send(subject, mail_body): try: msg = MIMEText(mail_body, 'plain', 'utf-8') msg['Subject'] = subject msg['From'] = SENDER msg['To'] = RECEIVER s = smtplib.SMTP(HOST, PORT) s.debuglevel = 0 s.login(SENDER, PWD) s.sendmail(SENDER, RECEIVER, msg.as_string()) s.quit() except smtplib.SMTPException as e: print(str(e)) def main(arg1, arg2): prefix = 'https://www.hostloc.com/' url = prefix + 'forum.php?mod=forumdisplay&fid=45&filter=hot' current_date = time.strftime("%Y-%m-%d", time.localtime()) content = requests.get(url).text soup = BeautifulSoup(content, 'html5lib') item_all_list = soup.select('th.new') items_title_list = [] for item in item_all_list: title = item.select_one('a.s.xst').get_text() href = item.select_one('a.s.xst').get('href') item_url = prefix + href items_title_list.append(title + '\n' + item_url) mail_send(subject=current_date + ' ' + 'Hostloc今日热帖', mail_body='\n\n'.join(items_title_list)) print('成功发送了一封邮件!') |
如何使用和部署请参考本站的这篇文章,注意上述代码在pip安装依赖的时候只需要安装beautifulsoup4
就行了,其它的就不用安装了。
kratos.min.css文件中
.k-main .details .toolbar { margin-top: 16px; padding: 20px; background-color: #fff; -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 2px rgba(0,0,0,.1); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
删除background-color: #fff; 即可解决白色背景问题。
@Lvtu 好的,我试试哈
@sharp097 大佬能发一下这个代码高亮插件吗,github看到的那个网址失效了
@3简单啊
github具体哪个链接呀,我是在https://iox7.com/18.html这里下载的哦~
@sharp097 谢谢!
谁的热情也不可能一直持续下去呀 :haha:
@梦之家 是呀是呀~