我解析Feed URL并获取内容。我想知道,如何获取给定feed的favicon并在django模板中呈现。从Feed内容获取图标
我是django和python的新手。我不知道如何做到这一点。
我正在使用feedparser来解析供稿网址。
我正在使用以下代码从文章内容中获取url列表。 NOw,我应该如何获取网站图标,因为在某些内容中的图标呈现为.png格式,并且有几个.png链接。如何区分哪一个是favicon?
import feedparser
import lxml.html as lh
import urllib2
#Import Feed for Parsing
d = feedparser.parse("http://www.popgadget.net/atom.xml")
# Print feed name
print d['feed']['title']
# Determine number of posts and set range maximum
posts = len(d['entries'])
# Collect Post URLs
for post in d['entries']:
link=post['link']
print('Parsing {0}'.format(link))
doc=lh.parse(urllib2.urlopen(link))
imgs=doc.xpath('//img[@class="bpImage"]')
for img in imgs:
print(img.attrib['src'])
ü可以编辑用U所提出的建议@Ignacio – Anshuma 2012-04-11 06:06:57