|
本文为 其乐用户(UID:270878) 发布的原创文章,转摘前请联系该用户获得许可
本帖最后由 270878 于 2025-1-31 09:19 编辑
前期提要:原始动机是我想“窃”走大佬们的游戏库,来回折腾发现最方便的做法还是
- 把他们的游戏库数据“窃”过来;
- 转换成 appid 列表;
- 导到自己愿望单里。
解决信息淹没问题的方法也很简单,确保你今天不添加其他游戏到愿望单里就好,用添加日期来做标记。然而之前常用的愿望单插件已经不再有导入愿望单的功能了,所以抱着试试看的心态让 ai 帮我写了一个,没想到居然真的写出来了。不过本人完全不懂 python 和 js,所有方法和工具都是用 ai 生成的,赞美现代科技!
本帖包含如下工具- 游戏库页面数据转 appid 列表.py 用来把 steam 用户游戏库页面的信息转化为 appid 列表;
- 一键导入愿望单 输入 appid 列表后自动导入到自己愿望单里去,如果这个游戏是你已经有的,则会自动移除愿望单后重新加入,用来统一这些游戏加入愿望单的时间。
之所以不整合成一个工具,是为了增加一键导入愿望单工具的适用范围。此外必备的有
窃取方法不需要任何插件,有考虑过让 ai 写个 python 来自动处理,但需要安装一堆库,不适合分享出来了。推荐使用 Chrome 浏览器:
- 选中心仪大佬,找到其游戏库页面,例如谜之声的游戏库;
- 在游戏库页面下右键选择“检查”,在“元素”标签页下搜索“data-profile-gameslist”,搜索结果等号后面的内容包含了大佬游戏库里全部的 appid 信息。
直接复制的话会显示“值过大,无法修改”,所以要在这里右键选择“以 HTML 格式修改”
直接将内容复制到本地,保存为 文件名.txt 即可。
至此大功告成!
将以下代码保存为 游戏库页面数据转 appid 列表.py
- import json
- import os
- import tkinter as tk
- from tkinter import filedialog
- def process_games_file():
- # 创建文件选择对话框
- root = tk.Tk()
- root.withdraw()
- # 选择输入文件
- input_path = filedialog.askopenfilename(
- title="选择游戏数据文件",
- filetypes=[("Text files", "*.txt"), ("All files", "*.*")]
- )
- if not input_path:
- print("操作已取消")
- return
- try:
- # 读取并处理文件
- with open(input_path, "r", encoding="utf-8") as f:
- html_content = f.read()
- # 提取JSON数据
- json_str = html_content.split('data-profile-gameslist="', 1)[1].split('"', 1)[0]
- json_str = json_str.replace('"', '"')
- data = json.loads(json_str)
- # 提取所有appid
- gcpd_ids = data.get("gcpdGames", [])
- rg_ids = [game["appid"] for game in data.get("rgGames", []) if "appid" in game]
- all_ids = sorted(set(gcpd_ids + rg_ids))
- # 生成输出文件名
- dir_name, file_name = os.path.split(input_path)
- base_name, ext = os.path.splitext(file_name)
- output_name = f"{base_name}(appid){ext}"
- output_path = os.path.join(dir_name, output_name)
- # 保存为逗号分隔格式
- with open(output_path, "w", encoding="utf-8") as f:
- f.write(",".join(map(str, all_ids))) # 修改此处为逗号分隔
- print(f"成功提取 {len(all_ids)} 个appid")
- print(f"已保存到: {output_path}")
- except Exception as e:
- print(f"处理失败: {str(e)}")
- print("请检查文件格式是否符合要求")
- if __name__ == "__main__":
- process_games_file()
复制代码
运行以上 python 程序后,选择刚刚保存的 文件名.txt ,会在相同文件夹下自动生成 文件名(appid).txt。至此大功告成!
打开自己的愿望单页面,右键点选“检查”,选择“控制台”标签复制以下代码输入- // == 在Steam愿望单页面(https://store.steampowered.com/wishlist/)执行 ==
- // 创建文件选择输入框
- const fileInput = document.createElement('input');
- fileInput.type = 'file';
- fileInput.accept = '.txt';
- fileInput.style.display = 'none';
- // 文件读取完成回调
- fileInput.onchange = async (e) => {
- const file = e.target.files[0];
- if (!file) return;
- const reader = new FileReader();
-
- reader.onload = async (e) => {
- const content = e.target.result;
- // 解析appid(支持逗号分隔/换行分隔)
- const appids = [...new Set(content.split(/[\n,]/)
- .map(id => id.trim())
- .filter(id => /^\d+$/.test(id))
- .map(Number))];
-
- await executeReset(appids);
- };
- reader.readAsText(file);
- };
- // 主执行函数
- async function executeReset(appids) {
- const sessionid = document.cookie.split('; ').find(c => c.startsWith('sessionid='))?.split('=')[1];
- if (!sessionid) return alert('请先登录Steam');
- const CONFIG = {
- delay: 100,
- retryCount: 1,
- forceRefresh: true
- };
- let successCount = 0;
- const total = appids.length;
-
- for (const [index, appid] of appids.entries()) {
- let retry = 0;
- while (retry < CONFIG.retryCount) {
- try {
- // 第一步:移除愿望单
- await fetch(`https://store.steampowered.com/api/removefromwishlist`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'X-Requested-With': 'XMLHttpRequest',
- 'Origin': 'https://store.steampowered.com',
- 'Referer': `https://store.steampowered.com/app/${appid}`
- },
- body: `appid=${appid}&sessionid=${sessionid}`
- });
-
- // 第二步:重新添加
- const addResponse = await fetch(`https://store.steampowered.com/api/addtowishlist`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'X-Requested-With': 'XMLHttpRequest',
- 'Origin': 'https://store.steampowered.com',
- 'Referer': `https://store.steampowered.com/app/${appid}`
- },
- body: `appid=${appid}&sessionid=${sessionid}`
- });
- const result = await addResponse.json();
- if (result.success) {
- console.log(`[${index+1}/${total}] ${appid}: ✅ 重置成功`);
- successCount++;
- break;
- } else {
- console.warn(`[${index+1}/${total}] ${appid}: ❌ 失败 (${result.strError})`);
- retry++;
- }
- } catch (e) {
- console.error(`[${index+1}/${total}] ${appid}: 🚨 网络错误`, e);
- retry++;
- }
- await new Promise(r => setTimeout(r, CONFIG.delay * (retry + 1)));
- }
- }
-
- console.log(`\n完成! 成功重置 ${successCount}/${total} 个游戏`);
- if (CONFIG.forceRefresh) {
- alert('操作完成,请手动刷新愿望单页面查看最新排序');
- window.location.reload();
- }
- }
- // 触发文件选择
- document.body.appendChild(fileInput);
- fileInput.click();
复制代码 选择仅含 appid 列表的 txt 文件,内容格式形如“20,50,70,130,220,280,320,360,...”。- 对于自己库里有的游戏,会显示“失败”
- 对于自己愿望单里已有的游戏,会移除愿望单后重新加入愿望单,以便使用添加日期作为标记。
以上程序自己实操了一遍,效果确实令人满意,故而分享出来。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
×
1、转载或引用本网站内容,必须注明本文网址:https://keylol.com/t987751-1-1。如发文者注明禁止转载,则请勿转载
2、对于不当转载或引用本网站内容而引起的民事纷争、行政处理或其他损失,本网站不承担责任
3、对不遵守本声明或其他违法、恶意使用本网站内容者,本网站保留追究其法律责任的权利
4、所有帖子仅代表作者本人意见,不代表本社区立场
|