我有一个简单的脚本来从subreddit获取图像:
唯一的问题是它正在拉动低分辨率拇指而不是高分辨率图像。
fetch('https://www.reddit.com/r/RoomPorn.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.link}">
<img src="${post.img}"/>
</a>`;
app.appendChild(node);
}
是否有可能取消高分辨率?
感谢您的时间,
答案 0 :(得分:1)
尝试:
fetch('https://www.reddit.com/r/RoomPorn.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.preview.images[0].source.url,
})))
btw post.data.url应该是原始来源的高分辨率图像链接。