[color=]1、更新修改Server酱->PUSHPLUS,
[color=]感谢
[color=]@hxy310。
[color=]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后的效果是这样的!