Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

python feedparser and getting multiple categories (category) within a item

import feedparser
import webbrowser

feed = feedparser.parse("https://seekingalpha.com/feed.xml")
feed_entries = feed.entries

for entry in feed.entries:

   article_title = entry.title
   article_link = entry.link
   article_published_at = entry.published # Unicode string
   article_published_at_parsed = entry.published_parsed # Time object
   e = entry.category

   print ("{}[{}]".format(article_title, article_link))
   print ("Published at {}".format(article_published_at))

In the above I'm only able to get the first of the category elements. I would like to list them all but most of all just the "symbol' ones.

Thank You

question from:https://stackoverflow.com/questions/66051634/python-feedparser-and-getting-multiple-categories-category-within-a-item

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

All the categories can be found in entry.tag but will not include the type to identify the symbol category you are looking for. If that is something you want adding that is simple.


for entry in feed.entries:
   # ...
   e = [t.get('term') for t in entry.tags]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...