蓝色天空网mbsky.com · 知识 · 实践 · 创造RSS · 本地阅读预览
教程 / XML / Web Service / RSS

RSS 阅读器:获取、去重与安全呈现

从本地feed实际读取条目,区分旧产品清单与当前浏览器能力。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

不同实现

阅读器可以是网络服务、桌面、移动应用或扩展,负责获取、去重、排序和展示。将feed URL复制到阅读器是常见订阅方式,但不同版本和扩展模块支持仍需测试。

NewsGator Online、RssReader、FeedDemon和blogbot是旧教程列举的产品,保留其在线、Windows或Outlook/IE插件等历史定位,不保证当前下载、免费、同步能力及兼容性仍相同。

已有阅读器时,可以从RSS或XML订阅图标取得真正feed的URL,再在阅读器中添加;不要把普通网页地址当作订阅数据。

从RSS图标取得订阅地址后,复制到实际阅读器;图标本身不是阅读器实现。

历史XML图标也可表示订阅入口,当前浏览器是否内置阅读需另核对。

浏览器能力已变化

Firefox内建feed预览及Live Bookmarks自2018年12月的64版移除,不能继续提示所有当前Firefox用户点击地址栏内置RSS图标。可按实际环境使用相应阅读器或扩展,图标链接只负责引导订阅。

本站reader.html从固定同源feed获取XML,使用DOM方法及textContent构建列表,只允许HTTP/HTTPS链接。读取不可信feed时还要限制大小、外部实体及资源访问,不能把所有订阅内容当可信网页执行。

真实观察范围

工程实际核对两个条目的标题、GUID、附件及空/不合法链接处理,并验证文本中的HTML字样不会执行。命令行解析、浏览器显示和真实媒体播放是不同证据,不把其中一项自动当作全部通过。

历史阅读器完整保留

名称旧资料定位现在的说明
NewsGator Online在线及相关同步功能历史清单,不保证当前服务
RssReaderWindows阅读器及多格式支持历史版本范围需另核对
FeedDemonWindows阅读器不保证旧下载或免费状态
blogbotOutlook/IE插件历史宿主,不当作当前推荐
Firefox内建feed支持曾有预览及Live Bookmarks64版于2018年12月移除

本站真实阅读分支

输入结果边界
feed.xml两个条目,PNG真实加载,输入框出现同源固定feed
十三个实例分别实际读取每例只验证明确目标
重复GUID显示一条并记录一次去重稳定标识
javascript链接不生成危险链接协议白名单
HTML样式描述textContent显示为文字不执行onerror等内容
评论/媒体实际本地目标可取得不代表所有阅读器实现相同

本章独立核心源码与验证步骤

html · 阅读源码
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><title>RSS 阅读实验 | 蓝色天空网</title><link rel="alternate" type="application/rss+xml" title="蓝色天空网学习更新" href="/feed.xml"></head><body><h1>蓝色天空网 mbsky.com</h1><p>订阅内容以文本安全显示;请使用本地学习feed。</p><a href="/feed">RSS订阅</a><img id="channel-image" hidden alt=""><h2 id="channel"></h2><div id="items"></div><div id="search"></div><p id="status" role="status"></p><script>
const files=["feed.xml", "unsafe.xml", "duplicates.xml", "examples/channel-required.xml", "examples/channel-category.xml", "examples/channel-generator.xml", "examples/channel-image.xml", "examples/channel-language.xml", "examples/channel-textInput.xml", "examples/channel-skipDays.xml", "examples/item-common.xml", "examples/item-comments.xml", "examples/item-enclosure.xml", "examples/item-guid.xml", "examples/item-pubDate.xml", "examples/item-source.xml"];
async function load(){try{const selected=new URLSearchParams(location.search).get('feed')||'feed.xml';if(!files.includes(selected))throw Error('不允许的本地feed');const response=await fetch('/'+selected,{headers:{Accept:'application/rss+xml'}});if(!response.ok)throw Error('HTTP '+response.status);const text=await response.text();if(text.length>1000000||/<!DOCTYPE/i.test(text))throw Error('输入超限或含DTD');const doc=new DOMParser().parseFromString(text,'application/xml');if(doc.querySelector('parsererror'))throw Error('XML解析失败');const channel=doc.querySelector('rss > channel');if(!channel)throw Error('不是RSS2频道');document.querySelector('#channel').textContent=channel.querySelector(':scope > title')?.textContent||'';const feedImage=channel.querySelector(':scope > image');if(feedImage){const imageURL=new URL(feedImage.querySelector('url').textContent);if(imageURL.origin===location.origin){const image=document.querySelector('#channel-image');image.alt=feedImage.querySelector('title').textContent;await new Promise((resolve,reject)=>{image.onload=resolve;image.onerror=()=>reject(Error('频道图像加载失败'));image.src=imageURL.href});image.hidden=false}}let unsafeLinks=0,duplicates=0;const seen=new Set();for(const item of channel.querySelectorAll(':scope > item')){const guid=item.querySelector(':scope > guid')?.textContent;if(guid&&seen.has(guid)){duplicates++;continue}if(guid)seen.add(guid);const section=document.createElement('section');const title=item.querySelector(':scope > title')?.textContent||'未命名条目';const href=item.querySelector(':scope > link')?.textContent;let node=document.createElement('span');if(href){const url=new URL(href,location.href);if(['http:','https:'].includes(url.protocol)){node=document.createElement('a');node.href=url.href;node.rel='noopener noreferrer'}else unsafeLinks++}node.textContent=title;section.append(node);const p=document.createElement('p');p.textContent=item.querySelector(':scope > description')?.textContent||'';section.append(p);for(const [field,label] of [['comments','查看讨论'],['enclosure','下载媒体']]){const element=item.querySelector(':scope > '+field);const href=field==='enclosure'?element?.getAttribute('url'):element?.textContent;if(href){const target=new URL(href,location.href);if(['http:','https:'].includes(target.protocol)){const a=document.createElement('a');a.href=target.href;a.textContent=label;a.rel='noopener noreferrer';if(field==='enclosure')a.download='';section.append(a)}}}document.querySelector('#items').append(section)}const ti=channel.querySelector(':scope > textInput');if(ti){const action=new URL(ti.querySelector('link').textContent);if(action.origin===location.origin){const form=document.createElement('form');form.method='get';form.action=action.href;const input=document.createElement('input');input.name=ti.querySelector('name').textContent;input.setAttribute('aria-label',ti.querySelector('description').textContent);const button=document.createElement('button');button.textContent=ti.querySelector('title').textContent;form.append(input,button);document.querySelector('#search').append(form)}}window.__rssResult={title:document.querySelector('#channel').textContent,items:document.querySelectorAll('#items section').length,unsafeLinks,duplicates,imageWidth:document.querySelector('#channel-image').naturalWidth,textInput:!!document.querySelector('#search form'),descriptions:[...document.querySelectorAll('#items p')].map(p=>p.textContent),inlineHandlers:document.querySelectorAll('#items [onerror]').length,passed:true};document.querySelector('#status').textContent='读取完成';}catch(error){window.__rssResult={passed:false,error:error.message};document.querySelector('#status').textContent=error.message}}
load();</script></body></html>
RSS 阅读器:获取、去重与安全呈现:核心实例

所需环境:RSS2.0固定资料;Python3.12 lxml;Edge回环阅读器

当前源码 SHA256:5f2ddf1b28af8fc11609699b25e795e3aac9aecffff0d3a06395329e90674253

下载本站示例源码
预期结果 · 待实际运行核验
  • 本章列明的RSS条件与实际解析/阅读结果一致
  • 不把替代图像、生成WAV或教学检查器冒充原站采集或全规范验收

常见错误与边界

  • 把item三项一律当成必填。
  • 把ttl分钟与HTTP缓存秒混同。
  • 把历史阅读器、目录或原图替代说成当前已验证。

练习与解答

增加一项只含描述的条目,保留稳定GUID,重新核对阅读器、字段与附件;再构造缺失enclosure属性。

展开参考解答

先检查XML与RSS2条件,再比较具体资源字节和实际阅读结果;未知扩展及外部服务不自动记为通过。

规范与官方依据