From fb69d65bef7d1587988b65f4d696b6e0dcc7c128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E8=B1=A1=E9=BC=BB=E5=AD=90=E9=95=BF=E5=8F=88?= =?UTF-8?q?=E9=95=BF?= Date: Wed, 20 Jul 2022 15:46:07 +0800 Subject: [PATCH 1/2] Update snb.js --- lib/v2/xueqiu/snb.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/v2/xueqiu/snb.js b/lib/v2/xueqiu/snb.js index d75f98d07c315..2bf10d568c1c4 100644 --- a/lib/v2/xueqiu/snb.js +++ b/lib/v2/xueqiu/snb.js @@ -8,12 +8,15 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', url, + headers: { + "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36 Edg/103.0.1264.37" + }, }); const data = response.data; - const pattern = /SNB.cubeInfo = (.+?);/; - const info = pattern.exec(data)[1]; - const obj = JSON.parse(info); + const pattern = /SNB.cubeInfo = {(.+)}/; + const info = pattern.exec(data); + const obj = JSON.parse("{" + info[1] + "}"); const rebalancing_histories = obj.sell_rebalancing.rebalancing_histories; const snb_title = obj.name + ' 的调仓历史'; const snb_description = obj.description; From 32ecb31dfc83fe71c49d39d8ff0550ee8157cb22 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 30 Jul 2022 20:07:06 +0000 Subject: [PATCH 2/2] fix: use random ua --- lib/v2/xueqiu/snb.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/v2/xueqiu/snb.js b/lib/v2/xueqiu/snb.js index 2bf10d568c1c4..c3cec12ea8f92 100644 --- a/lib/v2/xueqiu/snb.js +++ b/lib/v2/xueqiu/snb.js @@ -1,22 +1,21 @@ const got = require('@/utils/got'); const { parseDate } = require('@/utils/parse-date'); +const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' }); module.exports = async (ctx) => { const id = ctx.params.id; const url = 'https://xueqiu.com/p/' + id; - const response = await got({ - method: 'get', - url, + const response = await got(url, { headers: { - "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36 Edg/103.0.1264.37" + 'User-Agent': UA, }, }); const data = response.data; const pattern = /SNB.cubeInfo = {(.+)}/; const info = pattern.exec(data); - const obj = JSON.parse("{" + info[1] + "}"); + const obj = JSON.parse('{' + info[1] + '}'); const rebalancing_histories = obj.sell_rebalancing.rebalancing_histories; const snb_title = obj.name + ' 的调仓历史'; const snb_description = obj.description;