In [1]:
import feedparser
import pprint
import time
In [2]:
print(feedparser.__version__)
In [3]:
d_atom = feedparser.parse('http://gihyo.jp/feed/atom')
In [4]:
print(type(d_atom))
In [5]:
pprint.pprint(d_atom, depth=1)
In [6]:
print(d_atom['encoding'])
In [7]:
print(d_atom.get('encoding'))
In [8]:
print(list(d_atom.keys()))
In [9]:
d_rss1 = feedparser.parse('http://gihyo.jp/feed/rss1')
In [10]:
print(type(d_rss1))
In [11]:
pprint.pprint(d_rss1, depth=1)
In [12]:
d_rss2 = feedparser.parse('http://gihyo.jp/feed/rss2')
In [13]:
print(type(d_rss2))
In [14]:
pprint.pprint(d_rss2, depth=1)
In [15]:
feed = feedparser.parse('http://gihyo.jp/feed/atom')['feed']
In [16]:
print(type(feed))
In [17]:
pprint.pprint(feed)
In [18]:
print(feed['updated'])
In [19]:
print(type(feed['updated']))
In [20]:
t = feed['updated_parsed']
In [21]:
print(t)
In [22]:
print(type(t))
In [23]:
print(t.tm_year)
In [24]:
print(t.tm_mon)
In [25]:
print(t.tm_mday)
In [26]:
print(time.strftime('%Y-%m-%d %H:%M:%S', t))
In [27]:
entries = feedparser.parse('http://gihyo.jp/feed/atom')['entries']
In [28]:
print(type(entries))
In [29]:
print(len(entries))
In [30]:
entry = entries[0]
In [31]:
print(type(entry))
In [32]:
pprint.pprint(entry)
In [33]:
d = feedparser.parse('http://gihyo.jp/feed/atom')
In [34]:
urls = [entry['link'] for entry in d['entries']]
In [35]:
pprint.pprint(urls)
In [36]:
titles = [entry['title'] for entry in d['entries']]
In [37]:
pprint.pprint(titles)
In [38]:
dicts = [{'url': e['link'], 'title': e['title']} for e in d['entries']]
In [39]:
pprint.pprint(dicts)
In [40]:
print(dicts[0]['url'])
In [41]:
print(dicts[0]['title'])
In [42]:
print('\u3000' == ' ')
In [43]:
title = d['entries'][0]['title']
In [44]:
print(repr(title))
In [45]:
print(title)
In [46]:
print(title.replace('\u3000', ' '))
In [47]:
titles_space = [entry['title'].replace('\u3000', ' ') for entry in d['entries']]
In [48]:
pprint.pprint(titles_space)