Saturday, June 6, 2020

How to pull the hashtags from the RSS Feed URL

This article is about automating the manual process of copying the hashtags from a given RSS feed URL and pasting on social media such as Facebook. This article is divided into three parts:
In this article, we will learn how to pull the hashtags from FeedBurner, In order to get started with it, we need to install Feedparser python library. To install the Feedparser libraries, use below commands in the command prompt


pip install feedparser

Once you have installed feedparser, you can use the below code which extracts the title, link, hashtags using the following script. Copy the below code and save it with .py extension, execute in command prompt
import feedparser
import re
NewsFeed = feedparser.parse("http://feeds.feedburner.com/Especiallysports")
for item in NewsFeed.entries:
    print('Post Title :',item.title)
    print('Post Link :',item.feedburner_origlink)
    result = re.findall(r"#(\w+)", item.summary)
    aces = ["#" + suit for suit in result]
    hashtags = ' '.join(aces)
    print('Post hashtags :',hashtags)
   
The output should like this:

By default, the above script will throw 25 posts, to display only first 3 articles, you can use the below script
import feedparser
import re
count=0
NewsFeed = feedparser.parse("http://feeds.feedburner.com/Especiallysports")
for item in NewsFeed.entries:
    print('Post Title :',item.title)
    print('Post Link :',item.feedburner_origlink)
    result = re.findall(r"#(\w+)", item.summary)
    aces = ["#" + suit for suit in result]
    hashtags = ' '.join(aces)
    print('Post hashtags :',hashtags)
    print('')
    count=count+1
    if count>2:
        break
Output:

We have successfully able to pull the required data from the Feedburner to post it on the Facebook page. Let's move on and see how we can post on the Facebook page. In the next post, you will learn How to get the Access Token for Facebook Graph API?


EmoticonEmoticon