python实现小说更新提醒
测试网站:笔趣阁,网址为https://www.bswtan.com/登录网址为https://www.bswtan.com/login.php书架网址为https://www.bswtan.com/modules/article/bookcase.php
最后写个bat脚本,定时执行这个python程序,完美撒花。
其实想着最后转换成脚本猫后台脚本的,再搭配上web界面设置,可惜奥,暂时没有时间了,主要还是不会写,哈哈。
代码贴上。
```
# -*- coding: utf-8 -*-
"""
@Author :Cat
@Date : 2022年 05月 16日
@Introduction :A Lazy Cat
"""
import re
import requests
from bs4 import BeautifulSoup
def can_read(uri):
sss = session.get("https://www.bswtan.com/%s" % uri)
# soup = BeautifulSoup(get.text, "html.parser")
sss.encoding = "UTF-8"
soup = BeautifulSoup(sss.text, "html.parser")
soup_select = soup.select("#content")
# 小说长度
len1 = len(re.sub(r'<.*?>| ', '', str(soup_select)))
if len1 > 2000:
return True
else:
return False
if __name__ == '__main__':
url = "https://www.bswtan.com/login.php"
username = "你的账户名"
password = "你的密码"
payload = 'LoginForm%5Busername%5D={0}&LoginForm%5Bpassword%5D={1}'.format(username, password)
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
session = requests.session()
session.post(url, headers=headers, data=payload, timeout=3)
get = session.get("https://www.bswtan.com/modules/article/bookcase.php", timeout=3)
soup = BeautifulSoup(get.text, "html.parser")
select = soup.select('.grid').select('tr td >a')
book_name = select
up = soup.select('.grid').select('tr td span>a')
book = list(map(lambda x: x.string, book_name))
up = list(map(lambda x: (x.get("href"), x.string), up))
a = up
b = up
is_update = []
booklist = {}
read = can_read(a)
for i in range(len(a)):
booklist] = , b, (not a == b), ["否", "是"])]]
for (k, v) in booklist.items():
if v:
print("《%s》有更新!\n\t最新章节为:%s\t是否可读?:%s\n\t阅读进度为:%s" % (k, v, v, v))
``` ggnb 转化成后台脚本应该不难的 王一之 发表于 2022-5-20 18:12
转化成后台脚本应该不难的
哈哈,可惜我现在没什么时间,不然学一下就能写出来。
页:
[1]