晋江作者自查收藏数、评论数、点击量变化并利用微信发送给自己Python代码

最近心血来潮在晋江写了本扑街文学,大概10w字左右,虽然完全没人看,但毕竟是我的心血,如果有访问量的变化还是想及时知道,并且想要及时的消息提示——那么发wx就再好不过了。

那么就开整吧。

第一步:获得页面response

首先需要找到文章页面的url 类似以下这样

​​​​​​​https://my.jjwxc.net/backend/managenovel.php?novelid=0000000icon-default.png?t=M85Bhttps://my.jjwxc.net/backend/managenovel.php?novelid=

把你要查的那个页面的html扒下来。怎么扒?用下urllib贼简单

https://www.jianshu.com/p/63dad93d7000

需要登录怎么办?参考这个python爬虫19 | 爬虫遇到需要的登录的网站怎么办?用这3招轻松搞定! - 知乎

ok,这时候发现 需要的数据竟然在茫茫然的表格中跟html代码混在一起,这时候需要beautifulsoup登场了 参考Beautiful Soup4 之table数据提取_yf999573的博客-CSDN博客_bs4 table

要是需要定时执行怎么办呢,参考让 Python 程序定时执行的 8 种姿势~ - 知乎

第二步,把得到的信息发给自己:参考用Python实现自动发消息,自定义内容,太省事了!_退休的龙叔的博客-CSDN博客_python自动发消息脚本

直接上成品代码吧 简单易懂

import requests
from bs4 import BeautifulSoup
import re
import datetime
import time
import pyautogui as pag
import pyperclip

def check_recent():
    headers = {
        # 假装自己是浏览器,
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
        # 把你刚刚拿到的Cookie塞进来
        'Cookie':'你的cookie',
    }
    session = requests.Session()
#这里填写你自己文章的地址
    response = session.get('https://my.jjwxc.net/backend/managenovel.php?novelid=00000000&jsid=3000000_4000000', headers=headers)
    response.encoding = response.apparent_encoding  # 自动转码

    html = response.text
    soup = BeautifulSoup(html, features="html.parser")  # 创建一个BeautifulSoup对象
    table_node = soup.find_all('table')
    res = ''
    for table in table_node:
        res = res + table.get_text()
    #把空格去一去
    res = res.replace(' ', '')
    res = res.replace('\n', '')
    res = res.replace('\r', '')
    res = res.replace('\t', '')
    
    #用正则匹配一下
    match1 = re.findall("总点击:\d+\xa0总书评:\d+\xa0精华评:\d+\xa0收藏数:\d+", res)
    message = match1[0].split('\xa0')
    # print(message)

    new_info = []
    for i in [0,1,3]:
        new_info.append(int(message[i].split(':')[1]))
    return new_info


def compare_with_before(recent_info, new_info) :
    difference = [new_info[i] - recent_info[i] for i in range(3)]
    if difference[0] > 0:
        text = "总点击增加了" + str(difference[0])
        print(text)
        send_message(text)
    if difference[1] > 0:
        text = "总书评增加了" + str(difference[1])
        print(text)
        send_message(text)
    if difference[2] > 0:
        text = "收藏数增加了" + str(difference[2])
        print(text)
        send_message(text)


def send_message(text):

    #填入你自己的微信输入框坐标
    pag.click(-937, 95)  # 鼠标点击并定位到聊天窗口
    pyperclip.copy(text)  # 复制该行
    pag.hotkey("ctrl", "v")  # 粘贴,mac电脑则把ctrl换成command
    pag.typewrite("\n")  # 发送
    time.sleep(5)  # 每次发完间隔5s


def time_printer():
    now = datetime.datetime.now()
    ts = now.strftime('%Y-%m-%d %H:%M:%S')
    print('do func time :', ts)


if __name__ == '__main__':
    #初始化默认为0,也可以改成你的数据
    recent_info = [0,0,0]
    while True:
        time_printer()
        new_info = check_recent()
        compare_with_before(recent_info,new_info)
        recent_info = new_info
        time.sleep(1200)






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值