小言_互联网的博客

Python通知Epic白嫖游戏信息

373人阅读  评论(0)

每周都有免费游戏 - Epic Games
近期看到Epic在送游戏,目前每周都会有活动白嫖。

身为白嫖党,肯定要操作一下。

游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库

大致思路:

1、根据网站,获取可 “  白嫖  ”的游戏

2、处理相关信息,组成文本

3、发送到微信上,让我们知道。

1、查询网站

下面网页,会发布最新免费,可白嫖的游戏。我们爬取这些信息,进行判断

游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库

2、代码编写

1.我们爬取网页的数据

2.获取网页中所有游戏的信息

3.判断游戏信息是最新编辑的

4.汇总信息进行发送到微信

相关实例代码


  
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2022/12/29 16:33
  3. # @Author : 南宫乘风
  4. # @Email : 1794748404@qq.com
  5. # @File : epic_all.py
  6. # @Software: PyCharm
  7. import json
  8. import re
  9. import time
  10. import requests
  11. from bs4 import BeautifulSoup
  12. def get_url_info():
  13. url = 'https://indienova.com/gamedb/list/121/p/1'
  14. headers = {
  15. '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'}
  16. res = requests.get(url, headers=headers).text
  17. return res
  18. def check_epci_info( game_info_list):
  19. list_content = []
  20. for i in game_info_list:
  21. game_time = i[ 'game_time']
  22. if '小时前' in game_time[ 0]:
  23. content = f"中文名称:{i['game_zh']} <br/>" \
  24. f"英文名称:{i['game_en']} <br/>" \
  25. f"领取时间:{i['game_start']} <br/>" \
  26. f"发布时间:{i['game_time']}<br/><br/>"
  27. list_content.append(content)
  28. return list_content
  29. def parse_web_page( res):
  30. soup = BeautifulSoup(res, "html.parser")
  31. res.encode( 'UTF-8').decode( 'UTF-8')
  32. div_class = soup.find(name= 'div', attrs={ "id": "portfolioList"})
  33. # print(div_class[0])
  34. game_name = div_class.find_all(name= 'div', attrs={ "class": "col-xs-12 col-sm-6 col-md-4 user-game-list-item"})
  35. list_game = str(game_name).split( '<div class="col-xs-12 col-sm-6 col-md-4 user-game-list-item">')
  36. game_info_list = []
  37. for i in list_game[ 1:]:
  38. dict_info = {}
  39. # print('----------------------------------------------------------------------------------')
  40. game = BeautifulSoup(i, "html.parser")
  41. game_all_info = game.find(name= 'h4')
  42. game_name_zh = game_all_info.find_all(name= 'a')
  43. game_name_en = game_all_info.find_all(name= 'small')
  44. game_name_zh = re.findall( r'>(.+?)<', str(game_name_zh))
  45. game_name_en = re.findall( r'>(.+?)<', str(game_name_en))
  46. # print(game_name_zh, game_name_en)
  47. game_start_end = game.find(name= 'p', attrs={ "class": "intro"})
  48. game_start_end_new = game_start_end.find_all(name= 'span')
  49. game_edit_time = game.find(name= 'p', attrs={ "class": "text-date"})
  50. game_edit_time_new = game_edit_time.find_all(name= 'small')
  51. game_edit_time_new = str(game_edit_time_new).replace( " ", "").replace( "\n", " ")
  52. game_start_end_new = re.findall( r'>(.+?)<', str(game_start_end_new))
  53. game_edit_time_new = re.findall( r'>(.+?)<', str(game_edit_time_new))
  54. dict_info[ "game_zh"] = game_name_zh
  55. dict_info[ "game_en"] = game_name_en
  56. dict_info[ "game_start"] = game_start_end_new
  57. dict_info[ "game_time"] = game_edit_time_new
  58. game_info_list.append(dict_info)
  59. # print(game_start_end_new,game_edit_time_new)
  60. return game_info_list
  61. def send_to_epic_message( list_content):
  62. content = ''.join(list_content) + '\nhttps://indienova.com/gamedb/list/121/p/1'
  63. token = 'tokenxxxxxxxxxxxxxxxxxxxx'
  64. day_time = time.strftime( '%Y-%m-%d', time.localtime(time.time()))
  65. title = f'Epic免费游戏-{day_time}' # 改成你要的标题内容
  66. error_time = time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # 获取格式化的时间
  67. url = 'http://www.pushplus.plus/send'
  68. data = {
  69. "token": token, # 密钥
  70. "title": title, # 标题
  71. "content": content, # 发送的信息内容,这里我们是json数组
  72. "template": "markdown" # 数据类型为json
  73. }
  74. body = json.dumps(data).encode(encoding= 'utf-8')
  75. headers = { 'Content-Type': 'application/json'}
  76. request_result = requests.post(url, data=body, headers=headers)
  77. # print(request_result) # <Response [200]>
  78. if __name__ == '__main__':
  79. res = get_url_info()
  80. game_info_list = parse_web_page(res)
  81. list_content = check_epci_info(game_info_list)
  82. 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喜加一信息并自动发送到微信 - 知乎


转载:https://blog.csdn.net/heian_99/article/details/128495053
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场