每周都有免费游戏 - Epic Games
近期看到Epic在送游戏,目前每周都会有活动白嫖。
身为白嫖党,肯定要操作一下。
游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库
大致思路:
1、根据网站,获取可 “ 白嫖 ”的游戏
2、处理相关信息,组成文本
3、发送到微信上,让我们知道。
1、查询网站
下面网页,会发布最新免费,可白嫖的游戏。我们爬取这些信息,进行判断
游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库
2、代码编写
1.我们爬取网页的数据
2.获取网页中所有游戏的信息
3.判断游戏信息是最新编辑的
4.汇总信息进行发送到微信
相关实例代码
# -*- coding: utf-8 -*-
# @Time : 2022/12/29 16:33
# @Author : 南宫乘风
# @Email : 1794748404@qq.com
# @File : epic_all.py
# @Software: PyCharm
import json
import re
import time
import requests
from bs4 import BeautifulSoup
def get_url_info():
url = 'https://indienova.com/gamedb/list/121/p/1'
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'}
res = requests.get(url, headers=headers).text
return res
def check_epci_info(game_info_list):
list_content = []
for i in game_info_list:
game_time = i['game_time']
if '小时前' in game_time[0]:
content = f"中文名称:{i['game_zh']} <br/>" \
f"英文名称:{i['game_en']} <br/>" \
f"领取时间:{i['game_start']} <br/>" \
f"发布时间:{i['game_time']}<br/><br/>"
list_content.append(content)
return list_content
def parse_web_page(res):
soup = BeautifulSoup(res, "html.parser")
res.encode('UTF-8').decode('UTF-8')
div_class = soup.find(name='div', attrs={"id": "portfolioList"})
# print(div_class[0])
game_name = div_class.find_all(name='div', attrs={"class": "col-xs-12 col-sm-6 col-md-4 user-game-list-item"})
list_game = str(game_name).split('<div class="col-xs-12 col-sm-6 col-md-4 user-game-list-item">')
game_info_list = []
for i in list_game[1:]:
dict_info = {}
# print('----------------------------------------------------------------------------------')
game = BeautifulSoup(i, "html.parser")
game_all_info = game.find(name='h4')
game_name_zh = game_all_info.find_all(name='a')
game_name_en = game_all_info.find_all(name='small')
game_name_zh = re.findall(r'>(.+?)<', str(game_name_zh))
game_name_en = re.findall(r'>(.+?)<', str(game_name_en))
# print(game_name_zh, game_name_en)
game_start_end = game.find(name='p', attrs={"class": "intro"})
game_start_end_new = game_start_end.find_all(name='span')
game_edit_time = game.find(name='p', attrs={"class": "text-date"})
game_edit_time_new = game_edit_time.find_all(name='small')
game_edit_time_new = str(game_edit_time_new).replace(" ", "").replace("\n", " ")
game_start_end_new = re.findall(r'>(.+?)<', str(game_start_end_new))
game_edit_time_new = re.findall(r'>(.+?)<', str(game_edit_time_new))
dict_info["game_zh"] = game_name_zh
dict_info["game_en"] = game_name_en
dict_info["game_start"] = game_start_end_new
dict_info["game_time"] = game_edit_time_new
game_info_list.append(dict_info)
# print(game_start_end_new,game_edit_time_new)
return game_info_list
def send_to_epic_message(list_content):
content = ''.join(list_content) + '\nhttps://indienova.com/gamedb/list/121/p/1'
token = 'tokenxxxxxxxxxxxxxxxxxxxx'
day_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
title = f'Epic免费游戏-{day_time}' # 改成你要的标题内容
error_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # 获取格式化的时间
url = 'http://www.pushplus.plus/send'
data = {
"token": token, # 密钥
"title": title, # 标题
"content": content, # 发送的信息内容,这里我们是json数组
"template": "markdown" # 数据类型为json
}
body = json.dumps(data).encode(encoding='utf-8')
headers = {'Content-Type': 'application/json'}
request_result = requests.post(url, data=body, headers=headers)
# print(request_result) # <Response [200]>
if __name__ == '__main__':
res = get_url_info()
game_info_list = parse_web_page(res)
list_content = check_epci_info(game_info_list)
send_to_epic_message(list_content)
3、发送平台(pushplus)
微信公众号关注
pushplus(推送加)-微信消息推送平台
获取token进行配置即可。
4、定时任务
我们要把脚本部署到Linux操作环境 上。
首先记得安装依赖。pip install 模块
定时任务,每天10点运行一次。
0 10 * * * /usr/bin/python3 /opt/epic_send.py
参考文档:python获取steam/epic喜加一信息并自动发送到微信 - 知乎