8月 11

Python读Rss 不指定

adminleon , 14:39 , python , 评论(0) , 引用(0) , 阅读(126) , 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: ,
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]