Feed reading with Rust

created: 2021-01-17T03:27:21Z
modified: 2021-01-17T03:53:19Z

So as a follow up to web scraping in Rust I thought it important to point out how to consume an RSS feed which is a more stable way and more polite to the producer. RSS is unfortunately a dying format of producing feeds, but’s it’s much safer to pull from if it’s available and is generally easier on the websites resources to use. This uses the reqwest crate again and adds the rss crate.


reqwest = { version = "0.11", features = ["blocking", "json"] }
rss = "1.10.0"


use reqwest;
use rss::Channel;
use std::io::BufReader;

fn main() {
	let result = get_rss("http://feeds.bbci.co.uk/news/rss.xml");
	println!("{:#?}", result)

fn get_rss(url: &str) -> Channel {
	let feed = reqwest::blocking::get(url).unwrap();

	let channel = Channel::read_from(BufReader::new(feed)).unwrap();

I did take all the unwrapping shortcuts here, just a quick five minute example really. Throwing the feed into the buffer reader is the only trick, it just ensures the right type for the RSS crate.

<< Web scraping with Rust

  • Creative Commons License
  • Author: Gatewaynode