测试网站:笔趣阁,网址为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')[0].select('tr td >a')
book_name = select[0::2]
up = soup.select('.grid')[0].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[0::2]
b = up[1::2]
is_update = []
booklist = {}
read = can_read(a[1][0])
for i in range(len(a)):
booklist[book[i]] = [a[i][1], b[i][1], (not a[i] == b[i]), ["否", "是"][can_read(a[i][0])]]
for (k, v) in booklist.items():
if v[2]:
print("《%s》有更新!\n\t最新章节为:%s\t是否可读?:%s\n\t阅读进度为:%s" % (k, v[0], v[3], v[1]))