From b3d938032d8315403c7326c44266ee6d8d3233c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Mon, 11 Mar 2019 10:51:41 +0800 Subject: [PATCH] Hotfix: dajia (#1709) --- lib/routes/tencent/dajia/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/routes/tencent/dajia/index.js b/lib/routes/tencent/dajia/index.js index 1b4a56996..a8a581a9d 100644 --- a/lib/routes/tencent/dajia/index.js +++ b/lib/routes/tencent/dajia/index.js @@ -1,5 +1,6 @@ const axios = require('../../../utils/axios'); const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); module.exports = async (ctx) => { const listRes = await axios({ @@ -13,15 +14,17 @@ module.exports = async (ctx) => { const storyList = JSON.parse(listRes.data.slice(1, -2)).data; const resultItem = await Promise.all( storyList.map(async (story) => { - const url = story.n_mobile_url; + const mobileUrl = story.n_mobile_url; + const pcUrl = story.n_url; const item = { title: story.n_title, description: '', - link: url, + link: pcUrl, + guid: mobileUrl, author: story.name, pubDate: new Date(story.n_publishtime).toUTCString(), }; - const key = `tx-dajia: ${url}`; + const key = `tx-dajia: ${mobileUrl}`; const value = await ctx.cache.get(key); if (value) { @@ -29,13 +32,13 @@ module.exports = async (ctx) => { } else { const storyDetail = await axios({ method: 'get', - url: url, + url: pcUrl, headers: { - Referer: url, - 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', + Referer: pcUrl, }, + responseType: 'arraybuffer', }); - const $ = cheerio.load(storyDetail.data); + const $ = cheerio.load(iconv.decode(storyDetail.data, 'gb2312')); $('#articleContent img').each(function(_, item) { const $img = $(item); const src = $img.attr('src');