diff --git a/bot/WebCrawler.mjs b/bot/WebCrawler.mjs index d20dcf3..b4fb142 100644 --- a/bot/WebCrawler.mjs +++ b/bot/WebCrawler.mjs @@ -72,14 +72,17 @@ class WebCrawler extends HeroBot { //2. 解析 if (!data.cover) { - let minNaturalWidth = configs.minImageNaturalWidth ? configs.minImageNaturalWidth : 50; + let minNaturalWidth = configs.minImageNaturalWidth ? configs.minImageNaturalWidth : 200; + let imgSrc = '', imgType = ''; const imgElems = await hero.querySelectorAll('img'); if (imgElems) { - data.cover = await imgElems[0].src; - for (const imgEl of imgElems) { + //check image type supported + imgSrc = await imgEl.src; + imgType = common.getImageType(imgSrc); + //console.log('Completed: %s, naturalWidth: %s, width: %s', await imgEl.complete, await imgEl.naturalWidth, await imgEl.width); - if (await imgEl.complete && await imgEl.naturalWidth >= minNaturalWidth) { + if (imgType && await imgEl.complete && await imgEl.naturalWidth >= minNaturalWidth) { data.cover = await imgEl.src; //console.log('Cover got: %s', data.cover); break; diff --git a/lib/common.mjs b/lib/common.mjs index 5dc966b..d3dfd2c 100644 --- a/lib/common.mjs +++ b/lib/common.mjs @@ -53,7 +53,7 @@ export default { //support base64 format getImageType: function(url) { - let imgType = 'jpeg'; + let imgType = ''; if (/\.jp(e)?g/ig.test(url) || /image\/jp(e)?g/ig.test(url)) { imgType = 'jpeg';