The Research Nest
Published in

The Research Nest

Creating a program in GO to fetch the latest news in any given topic

My SLTP Walkthrough: Part 4

Photo by Roman Kraft on Unsplash
const url string = "https://www.google.com/alerts/feeds/11016768836951419989/3365315696613981974"
// My complete test.go file at this momentpackage mainimport (
"fmt"
"github.com/mmcdole/gofeed"
)
const url string = "https://www.google.com/alerts/feeds/11016768836951419989/3365315696613981974"func main() {
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(url)
fmt.Println(feed.Title)
}
//Function to fetch news articles from RSS feedfunc fetchNews(url string) []*gofeed.Item {
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(url)
return feed.Items
}
//Testing the function in main()
func main() {
temp := fetchNews(url)
fmt.Println(temp[2].Content) //prints content of the 3rd item
}

What next?

--

--

Empowering humanity with exclusive insights.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
XQ

Tech 👨‍💻 | Life 🌱 | Careers 👔 | Poetry 🖊️