python自动检索buff平台低价商品

目录

前言

一、如何获取低价标准

二、代码实现

1.引入库

2.获取商品数据

3.检索商品历史价格

4.计算低价商品

5.通知及显示

6.执行主程序

总结​​​​​​​

前言

buff平台的商品价格有较大的波动范围,在特定的时间段(寒暑假等)还会有大幅的增长,如何选择低价商品进行购入,在高价时卖出,博取相当收益。buff提供的历史价格数据可以作为重要的参考依据。

这篇文章主要介绍了如何使用python获取buff商品历史价格,通过计算,对比当前价格和历史价格的大小,预警低价商品。


一、如何获取低价标准

在buff中,每个商品都存在价格趋势,普通用户可以获取一个月内商品的60个价格点(每天2个价格点),充值plus会员后,甚至可以获取6个月的历史价格数据。虽然价格不是连续线性的,但是也具有一定的参考价值。题主没有充会员,就用1个月作为参考哈哈。

buff价格趋势曲线图

二、代码实现

1.引入库

import re
import requests as req
import time,random,winsound,sendmessage,numpy as np
from datetime import datetime

class CS():
    def __init__(self):
        self.nowtime = datetime.now()
        self.goodsurl = 'https://buff.163.com/api/market/goods'
        self.pricehistoryurl = 'https://buff.163.com/api/market/goods/price_history/buff'
        self.my_headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
            "Cookie": "yourcookie",#你自己的cookie
            "Host": "buff.163.com",
            "Referer": "https://buff.163.com/market/?game=csgo",
            "X-Requested-With": "XMLHttpRequest"
        }

这里用到的两个api

 self.goodsurl = 'https://buff.163.com/api/market/goods'

 self.pricehistoryurl = 'https://buff.163.com/api/market/goods/price_history/buff'

分别是查找符合商品的api和获取历史价格的api

2.获取商品数据

    def SearchGoods(self, weaponame):  # 搜索符合价格标准的weaponlist商品,返回商品id等数据
        nowtime = self.nowtime.timestamp()
##############参数调整################
        param = {
            'game': 'csgo',
            'page_size': 80,
      
### Python 实现网易BUFF CSGO 饰品扫货脚本 对于在网易BUFF平台上进行CSGO饰品扫货的任务,可以利用Python编写自动化脚本来实现这一目标。下面是一个简化版本的代码示例,该例子展示了如何通过网络请求获取商品信息并处理这些数据。 #### 准备工作 为了能够顺利运行此程序,需先安装必要的库文件: ```bash pip install requests json pandas ``` #### 获取页面总数与商品详情 考虑到buff存在页码显示异常的情况[^2],可以通过发送带有较大`page_num`值(例如100)的请求来获得真实的总页数以及每一页的具体内容。 ```python import requests import json def get_total_pages_and_items(): url = "https://buff.163.com/api/market/goods" params = { 'game': 'csgo', 'page_num': 100, 'sort_by': 'default', '_': '' } response = requests.get(url, params=params).json() total_page = response['data']['total_page'] items_per_page = response['data']['items'] return total_page, items_per_page ``` #### 解析字符串到列表 当遇到形如`"[a,b,c]"`这样的字符串表示法时,可以直接采用`json.loads()`方法将其转换成真正的Python列表对象,而无需手动分割字符[^1]。 ```python from ast import literal_eval def parse_string_to_list(string_representation): try: result = json.loads(string_representation) except ValueError as e: # Fallback to using literal eval if JSON fails (for non-standard strings like '[a, b]') result = literal_eval(string_representation) return result ``` #### 数据筛选逻辑 根据个人需求设定过滤条件,比如只关注特定范围内的价格区间或是某些稀有的皮肤种类等。 ```python def filter_goods(items, min_price=None, max_price=None, names=[]): filtered = [] for item in items: price = float(item["sell_min_price"]) name_match = not names or any(name.lower() in item["name"].lower() for name in names) within_price_range = True if min_price is not None and price < min_price: within_price_range = False elif max_price is not None and price > max_price: within_price_range = False if name_match and within_price_range: filtered.append({ "id": item["id"], "name": item["name"], "price": f"{price:.2f}" }) return filtered ``` #### 主函数执行流程 最后一步就是组合上述各个部分的功能,在主循环里调用它们完成整个过程。 ```python if __name__ == "__main__": pages, sample_items = get_total_pages_and_items() all_filtered_results = [] for page in range(1, pages + 1): _, current_page_items = get_total_pages_and_items(page) selected_names = ["StatTrak", "Souvenir"] # Example filters results = filter_goods(current_page_items, min_price=1, max_price=50, names=selected_names) all_filtered_results.extend(results) print(f"Found {len(all_filtered_results)} matching goods.") ```
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值