8月 11

Python读Rss 不指定

adminleon , 14:39 , python , 评论(0) , 引用(0) , 阅读(113) , Via 本站原创 | |
突然想写个Python读Rss的程序看看。

代码
----------------------------------------------------------

#!d:\Python24\python.exe
#-*- encoding: gb2312 -*-
import os, sys, string
import feedparser




furl='http://www.gjjblog.com/feed.php'


#模拟浏览器
feedparser.USER_AGENT = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"



try:
  d = feedparser.parse(furl)
  s= d.encoding



  print d.feed.title.encode(s)
  
  j=len(d['items'])

  print j
  
  for r in range(j):
    e=d['items'][r]
    xtitle=e['title']
    print e['link']
    print e['description']
    
    

except Exception, e:
  print "错误 => "+str(e)

Tags: ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]