网易buff饰品折扣对比(无封号风险)
原理
手动点击buff饰品页,控制台导出请求,经过程序处理后,用表格筛选排序。不用爬虫,数据要自己点,没有封号风险。本质上就是把关键数据拿出来方便对比。
小白
1.获取buff数据
buff官网
登录,F12打开控制台,网络,清空。
筛选需要的饰品,建议按在售数量排序,后面都是数量少的就不用看了。注意不要点详情页。
控制台导出Har文件,命名为buff.163.com.js,打开文件,开头加上const buff =
2.程序处理
新建html文件,和buff.163.com.js在一个文件夹。
用记事本等编辑器打开文件,复制代码后,保存关闭。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>buff</title>
</head>
<script type="text/javascript" src="buff.163.com.js"></script>
<body>
<div id="app"></div>
</body>
<script>
let discounts = '名称\t在售\tbuff\tsteam\t折扣\r\n'
const goods = buff.log.entries
.filter((item) => item._resourceType === 'xhr')
.filter((item) => item.request.url.startsWith('https://buff.163.com/api/market/goods'))
goods.forEach((good) => {
const items = JSON.parse(good.response.content.text).data.items
items.forEach((item) => {
discounts += `${item.name}\t${item.sell_num}\t${item.sell_min_price}\t${
item.goods_info.steam_price_cny
}\t${((item.sell_min_price / item.goods_info.steam_price_cny) * 1.15).toFixed(2)}\r\n`
})
})
console.log(discounts)
</script>
</html>
用浏览器打开文件,F12打开控制台,点击这一块输出,Ctrl + A,Ctrl + C。
3.表格展示
复制到表格,开头的buff.html:24可以删一下,数据-筛选。按需数字筛选,在折扣列排序。
Vue + Element UI
1.获取buff数据
同上,区别是保存时文件后缀是json,不用加代码。
2.程序处理展示
懂的都懂。
<template>
<div :style="{ width: '1000px', margin: 'auto', marginTop: '100px' }">
最低价
<el-input-number v-model="minBuff" :step="10" step-strictly></el-input-number>
最高价
<el-input-number v-model="maxBuff" :step="10" step-strictly></el-input-number>
最低在售
<el-input-number v-model="minNum" :step="100" step-strictly></el-input-number>
<el-button style="margin-left: 20px" type="primary" @click="changeCondition(true)"
>全部</el-button
>
<el-button type="success" @click="changeCondition(false)">常用</el-button>
<el-table
:data="filterDiscounts"
ref="table"
border
:default-sort="{ prop: 'discount', order: 'ascending' }"
:style="{ width: '1000px', marginTop: '20px' }"
>
<el-table-column type="index" align="center" width="60" label="序号" />
<el-table-column sortable label="名称" prop="name" show-overflow-tooltip min-width="100" />
<el-table-column sortable label="在售" prop="num" width="100" />
<el-table-column sortable label="buff" prop="buff" width="100" />
<el-table-column sortable label="steam" prop="steam" width="100" />
<el-table-column sortable label="折扣" prop="discount" width="100" />
<el-table-column #default="{ row }" label="buff链接" prop="buffUrl" width="100">
<el-link type="primary" :underline="false" @click="openUrl(row.buffUrl)"> buff </el-link>
</el-table-column>
<el-table-column #default="{ row }" label="steam链接" prop="steamUrl" width="100">
<el-link type="primary" :underline="false" @click="openUrl(row.steamUrl)"> steam </el-link>
</el-table-column>
</el-table>
</div>
</template>
<script>
import buff from './buff.163.com.json'
export default {
name: 'buff-spider',
data() {
return {
buff,
minBuff: 0,
maxBuff: 100,
minNum: 0,
discounts: []
}
},
computed: {
filterDiscounts() {
return this.discounts.filter(
(item) => item.buff >= this.minBuff && item.buff <= this.maxBuff && item.num > this.minNum
)
}
},
watch: {
filterDiscounts() {
this.$nextTick(() => {
this.$refs.table.sort('discount', 'ascending')
})
}
},
created() {
this.getDiscount()
},
methods: {
getDiscount() {
let discounts = []
const goods = this.buff.log.entries
.filter((item) => item._resourceType === 'xhr')
.filter((item) => item.request.url.startsWith('https://buff.163.com/api/market/goods'))
goods.forEach((good) => {
const items = JSON.parse(good.response.content.text).data.items
const discount = items.map((item) => {
return {
name: item.name,
num: item.sell_num,
buff: item.sell_min_price,
steam: item.goods_info.steam_price_cny,
discount: ((item.sell_min_price / item.goods_info.steam_price_cny) * 1.15).toFixed(2),
buffUrl: `https://buff.163.com/goods/${item.id}`,
steamUrl: item.steam_market_url
}
})
discounts = discounts.concat(discount)
})
this.discounts = discounts
},
changeCondition(isAll) {
this.minBuff = isAll ? 0 : 10
this.maxBuff = isAll ? 100 : 50
this.minNum = isAll ? 0 : 1000
},
openUrl(url) {
window.open(url)
}
}
}
</script>