You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo应用:如何从RSS Feed获取更多文章数据?

为什么RSS Feed只返回10条内容,以及如何获取更多文章

原因分析

这是网站对RSS Feed的默认输出限制,多数新闻类网站会限制RSS返回的条目数量(通常为10-20条),目的是控制服务器带宽消耗,同时引导用户访问官网浏览更多内容。你未找到分页信息,说明该RSS源本身不支持分页扩展,无法通过调整参数直接获取更多内容。

解决办法

  • 抓取网站的加载更多接口
    官网的「加载更多」功能依赖前端异步请求内部API实现。你可以通过浏览器开发者工具(F12)打开Network标签,滚动页面触发加载更多,找到对应的XHR/Fetch请求,直接在应用中调用该接口。这类接口一般返回JSON格式数据,比RSS更易解析,且能获取完整文章列表。
    示例修改后的请求函数:

    const fetchMoreArticles = async (page = 1, setFeedData, setLoading) => {
      setLoading(true);
      try {
        // 替换为实际抓到的API地址及参数
        const response = await axios.get('https://www.drive.com.au/api/news/list', {
          params: { page, limit: 20 }
        });
        // 根据接口返回结构映射为FeedItem格式
        const newItems = response.data.data.map(item => ({
          title: item.title,
          link: `https://www.drive.com.au${item.url}`,
          pubDate: item.publishedAt,
          description: item.summary
        }));
        setFeedData(prev => [...prev, ...newItems]);
        setLoading(false);
      } catch (error) {
        console.error('获取更多文章失败:', error);
        setLoading(false);
      }
    };
    
  • 网页内容抓取(需注意合规性)
    如果没有公开内部API,可考虑抓取官网HTML页面,使用cheerio等HTML解析库提取文章内容。但需先查看网站的robots.txt和使用条款,确保抓取行为符合规定。在React Native Expo中,可通过axios获取HTML后解析:

    import cheerio from 'cheerio';
    
    const fetchArticlesFromPage = async (pageUrl = 'https://www.drive.com.au/news/', setFeedData, setLoading) => {
      setLoading(true);
      try {
        const response = await axios.get(pageUrl);
        const $ = cheerio.load(response.data);
        const items = [];
        // 根据网页实际DOM结构调整选择器
        $('.sc-fzqBZW').each((i, el) => {
          items.push({
            title: $(el).find('h3').text().trim(),
            link: `https://www.drive.com.au${$(el).find('a').attr('href')}`,
            pubDate: $(el).find('.sc-fzqNqU').text().trim()
          });
        });
        setFeedData(prev => [...prev, ...items]);
        setLoading(false);
      } catch (error) {
        console.error('抓取页面失败:', error);
        setLoading(false);
      }
    };
    

    注意:此方法依赖网站DOM结构,若网站更新布局,解析逻辑需同步调整。

  • 联系网站官方
    可尝试联系网站管理员,询问是否提供支持更多条目的RSS源或开放开发者API,但这种方式成功率较低。

内容的提问来源于stack exchange,提问作者AlphaT-30

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 08:53:10