吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3204|回复: 28
收起左侧

[Python 原创] 爬取喜加一游戏,Github+PUSHPLUS,每日推送到微信

  [复制链接]
平Fan_d世界 发表于 2023-9-4 19:54
本帖最后由 平Fan_d世界 于 2023-9-16 15:39 编辑

2023-9-15更新:
1、更新修改Server酱->PUSHPLUS,感谢@hxy310。
2、修正无游戏+1时的错误。
3、修改一些错误代码。

1、爬取喜加一,地址:https://steamstats.cn/xi使用了BeautifulSoup库,使用pip安装,代码>> pip install beautifulsoup4
[Python] 纯文本查看 复制代码
import requests
from bs4 import BeautifulSoup

##Server酱更改为PUSHPLUS,此段代码注释了###Server酱推送模块,PUSH_KEY替换自己的
#def send_message_fangtang(_item,_message):
#        PUSH_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  #
#        api = 'https://sctapi.ftqq.com/' + PUSH_KEY + '.send'
#        _d = {
#                "title": _item,
#                "desp": _message
#                }
#       req = requests.post(api,data = _d)
#       #print(req.text)

#PushPlus推送模块
def pushplus(_item, _message):
    token = sys.argv[1]    #隐藏token码,参考楼下代码
    api = 'http://www.pushplus.plus/send'
    _d = {
        "token": token,
        "title": _item,
        "content": _message
    }
    req = requests.post(api, data=_d)
    #print(req.text)

#爬取代码
url='https://steamstats.cn/xi'
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.41'}

r=requests.get(url,headers=headers)
r.raise_for_status()
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text, "html.parser")
tbody=soup.find('tbody')
desp="🎉当前可领限时免费游戏🎉"+'\n'
#print(tbody)
if tbody is not None:
    tr=tbody.find_all('tr')
    i=1
    for tr in tr:
        td=tr.find_all('td')
        name=td[1].string.strip().replace('\n', '').replace('\r', '')
        gametype=td[2].string.replace(" ","").replace('\n', '').replace('\r', '')
        start=td[3].string.replace(" ","").replace('\n', '').replace('\r', '')
        end=td[4].string.replace(" ","").replace('\n', '').replace('\r', '')
        time=td[5].string.replace(" ","").replace('\n', '').replace('\r', '')
        oringin=td[6].find('span').string.replace(" ","").replace('\n', '').replace('\r', '')
        sp=str(td[6]).split('"')
        http=sp[3]
        
        desp=desp+"序号:"+str(i)+'\n'+"游戏名称:"+name+'\n'+"类型:"+gametype+'\n'+"开始时间:"+start+'\n'+"结束时间:"+end+'\n'+"是否永久:"+time+'\n'+"平台:"+oringin+'\n'+"链接:"+http+'\n'
        i=i+1
    else:
        desp=desp+"无"
#send_message_fangtang("今日喜加一",desp)
pushplus("✨今日喜加一✨",desp)
#print(desp)       


2、Github Ations,new workflows新建main.yml
[Shell] 纯文本查看 复制代码
name: happy plus one

on:
  push:
    branches:
      - main
  schedule:   
    - cron:  23 23 * * *   #国际标准时间,北京时间+8

jobs:
  my_job:
    runs-on: ubuntu-latest
    steps:
      - name: 'checkout codes'
        uses: actions/checkout@v2
      - name: 'set up python'
        uses: actions/setup-python@v2
        with:
         python-version: ${{ matrix.python-version }}
      - name: requirements
        run: |
         python -m pip install --upgrade pip
         pip install beautifulsoup4
      - name: 'Epic/steam happy +1'
         run: |
          python ${{ github.workspace }}/happy_plus_one.py ${{ secrets.PUSHPLUS_TOKEN }}  #你的PUSHPLUS TOKEN



3、储存库-Settings-Secrets and variables-Actions-New repository secret Name填入你的TOKEN

复制第一步的happy_plus_one.py文件到Github,大功告成!执行没问题的!

效果差不多是这样,还有个链接地址是后改的,今天的推送次数到了,没有在图片上。


PUSHPLUS后的效果是这样的!




免费评分

参与人数 5吾爱币 +10 热心值 +5 收起 理由
philhuan + 1 谢谢@Thanks!
卡兹sama + 1 + 1 用心讨论,共获提升!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
13668377258 + 1 + 1 我很赞同!
莫奇 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

hxy310 发表于 2023-9-5 00:54
本帖最后由 hxy310 于 2023-9-5 01:05 编辑

根据楼主的代码,我改良了一下,将token放入了Actions secrets and variables,这样不会暴露token,防止有人利用token推送垃圾信息,并且我将Server酱换成了pushplus,大家可以选择性使用。
需要打开你的储存库-Settings-Secrets and variables-Actions-New repository secret Name填TOKEN,底下的值就将你的推送秘钥粘贴进去就行了。

[Shell] 纯文本查看 复制代码
name: Happy_Plus_One
on:
  workflow_dispatch:
  
  schedule:  
     - cron:  0 1 * * *   #国际标准时间,北京时间+8
jobs:
  my_job:
    runs-on: ubuntu-latest
    steps:
      - name: 'checkout codes'  #检测代码
        uses: actions/checkout@v2
      - name: 'set up python'  #配置python
        uses: actions/setup-python@v2
        with:
         python-version: ${{ matrix.python-version }}
      - name: requirements  #配置库
        run: |
         python -m pip install --upgrade pip
         pip install beautifulsoup4
      - name: 'Epic/steam happy +1'  #运行py
        run: |
          python happy_plus_one.py ${{ secrets.TOKEN }}


[Asm] 纯文本查看 复制代码
import sys
import requests
from bs4 import BeautifulSoup

# PushPlus推送模块
def pushplus(_item, _message):
    token = sys.argv[1]
    api = 'http://www.pushplus.plus/send'
    _d = {
        "token": token,
        "title": _item,
        "content": _message
    }
    req = requests.post(api, data=_d)
    print(req.text)

# 爬取代码
url = 'https://steamstats.cn/xi'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.41'}

r = requests.get(url, headers=headers)
r.raise_for_status()
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text, "html.parser")
tbody = soup.find('tbody')
tr = tbody.find_all('tr')
i = 1

for tr in tr:
    td = tr.find_all('td')
    name = td[1].string.strip().replace('\n', '').replace('\r', '')
    gametype = td[2].string.replace(" ", "").replace('\n', '').replace('\r', '')
    start = td[3].string.replace(" ", "").replace('\n', '').replace('\r', '')
    end = td[4].string.replace(" ", "").replace('\n', '').replace('\r', '')
    time = td[5].string.replace(" ", "").replace('\n', '').replace('\r', '')
    origin = td[6].find('span').string.replace(" ", "").replace('\n', '').replace('\r', '')

    sp = str(td[6]).split('"')
    http = sp[3]
    desp = "序号:" + str(i) + '\n\r' + "游戏名称:" + name + '\n\r' + "类型:" + gametype + '\n\r' + "开始时间:" + start + '\n\r' + "结束时间:" + end + '\n\r' + "是否永久:" + time + '\n\r' + "平台:" + origin + '\n\r' + "链接:" + http + '\n\r'

    # 推送
    pushplus("今日喜加一", desp)
    print(desp)


如果想使用Server酱,将我第二段的代码第1到第15行替换即可。
[Python] 纯文本查看 复制代码
import sys
import requests
from bs4 import BeautifulSoup
#Server酱推送模块,PUSH_KEY替换自己的
def send_message_fangtang(_item,_message):
        token = sys.argv[1]
        api = 'https://sctapi.ftqq.com/' + token + '.send'
        _d = {
                "title": _item,
                "desp": _message
                }
        req = requests.post(api,data = _d)
        #print(req.text)





免费评分

参与人数 2吾爱币 +3 热心值 +2 收起 理由
三滑稽甲苯 + 1 + 1 用心讨论,共获提升!
平Fan_d世界 + 2 + 1 感谢!

查看全部评分

shuai2051 发表于 2023-9-7 10:00
适配青龙面板,需要在脚本同目录存在notify.py文件,且在配置文件设置过相应推送变量,效果如下图

效果图

效果图
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-
"""
cron: 48 7 * * *
new Env('epic 今日喜加一');
"""
import time
import re
import requests
import logging
import random
import os
import sys
from os import environ, system, path
from bs4 import BeautifulSoup

# 加载通知
def load_send() -> None:
    logging.info("加载推送功能中...")
    global send
    send = None
    cur_path = os.path.abspath(os.path.dirname(__file__))
    sys.path.append(cur_path)
    if os.path.exists(cur_path + "/notify.py"):
        try:
            from notify import send
        except Exception:
            send = None
            logging.info(f"❌加载通知服务失败!!!\n{traceback.format_exc()}")
    else:
        logging.info(f"❌加载通知服务失败!!!\n")
# 爬取代码
def main():
    url = 'https://steamstats.cn/xi'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.41'}

    r = requests.get(url, headers=headers)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
    soup = BeautifulSoup(r.text, "html.parser")
    tbody = soup.find('tbody')
    tr = tbody.find_all('tr')
    i = 1
    # desp="今日喜加一"+'\n'
    for tr in tr:
        td = tr.find_all('td')
        name = td[1].string.strip().replace('\n', '').replace('\r', '')
        gametype = td[2].string.replace(
            " ", "").replace('\n', '').replace('\r', '')
        start = td[3].string.replace(" ", "").replace('\n', '').replace('\r', '')
        end = td[4].string.replace(" ", "").replace('\n', '').replace('\r', '')
        time = td[5].string.replace(" ", "").replace('\n', '').replace('\r', '')
        oringin = td[6].find('span').string.replace(
            " ", "").replace('\n', '').replace('\r', '')

        sp = str(td[6]).split('"')
        http = sp[3]
        res = "序号:"+str(i)+'\n\r'+"游戏名称:"+name+'\n\r'+"类型:"+gametype+'\n\r'+"开始时间:"+start + \
            '\n\r'+"结束时间:"+end+'\n\r'+"是否永久:"+time+'\n\r' + \
            "平台:"+oringin+'\n\r'+"链接:"+http+'\n\r'
    # print(res)
    result = f"{res}"
    send('今日喜加一', result)

if __name__ == "__main__":
     # 加载通知
    load_send()
    time.sleep(random.randint(5, 10))
    main()



免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
平Fan_d世界 + 2 + 1 热心回复!

查看全部评分

LeslieLau 发表于 2023-9-4 21:45
罩到胸前必有沟 发表于 2023-9-4 19:58
很厉害!
fscc无误 发表于 2023-9-4 20:01
这是什么????
GodRui2023 发表于 2023-9-4 20:45
萌新看得一脸懵 待我多看几遍
头像被屏蔽
moruye 发表于 2023-9-4 21:11
提示: 作者被禁止或删除 内容自动屏蔽
AaronZero 发表于 2023-9-4 22:12
可以,这个牛
雾都孤尔 发表于 2023-9-4 23:39
学习下,感谢分享。
一条小渣团OvO 发表于 2023-9-5 06:58
LeslieLau 发表于 2023-9-4 21:45
有个APP小黑盒,上面有领取功能

推荐小黑盒!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-24 00:52

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表