1
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import cgi
import string
import feedparser

count = 0
print "Content-Type: text/html\n\n"
print """<PRE><B>WORK MAINTENANCE/B></PRE>"""


d = feedparser.parse("http://www.hep.hr/ods/rss/radovi.aspx?dp=zagreb")


for opis in d:
    try:
          print """<B>Place/Time:</B> %s<br>""" % d.entries[count].title
          print """<B>Streets:</B> %s<br>""" % d.entries[count].description
          print """<B>Published:</B> %s<br>""" % d.entries[count].date
          print "<br>"
          count+= 1
    except:
        pass

我对 CGI 和 paython 脚本有疑问。在终端脚本下运行得很好,除了“IndexError:list index out of range”,我为此设置了通行证。但是当我通过 CGI 运行脚本时,我只得到 WORK MAINTENANCE 行和 d.entries[count].title 中的第一行重复 9 次?好混乱……

另外,我如何在 feedparser 中设置对克罗地亚(巴尔干)字母的支持;č,ć,š,ž,đ ? # - - 编码:utf-8 - - 不工作,我正在运行 Ubuntu 服务器。

提前感谢您的帮助。

问候。

4

2 回答 2

0
for opis in d:
    try:
          print """<B>Place/Time:</B> %s<br>""" % d.entries[count].title

您没有在输出中使用“opis”。

尝试这样的事情:

for entry in d.entries:
    try:
        print """<B>Place/Time:</B> %s<br>""" % entry.title
        ....
于 2010-08-03T03:39:30.067 回答
0

Oke 有另一个问题,我手动输入的文本会显示在 CGI 上,但 RSS 网页不会。因此,您需要在编写之前进行编码:

# -*- coding: utf-8 -*-
import sys, os, string
import cgi
import feedparser
import codecs

d = blablablabla

print "Content-Type: text/html; charset=utf-8\n\n"
print

for entry in d.entries:
    print """%s""" % entry.title.encode('utf-8')
于 2010-08-06T18:19:39.860 回答