1

我使用feedparser模块成功地解析了来自国家飓风中心的 RSS 提要:

import feedparser
feedparser.parse('https://www.nhc.noaa.gov/gis-at.xml') #Works Fine
feedparser.parse('https://www.nhc.noaa.gov/gis-ep.xml') #Works Fine

但是,当我尝试从中太平洋飓风中心读取表面上相似的提要时,我生成了一个 KeyError:

feedparser.parse('http://www.prh.noaa.gov/cphc/gis-cp.xml') #Doesn't work

这是 feedparser 的错误吗?CPHC 的 Feed 格式是否错误?有没有我忘记指定的选项?问题似乎在于没有一个名为“where”的键,但我不知道为什么这对 NHC 提要来说不是问题。堆栈复制如下:

>>>  import feedparser
>>>  feedparser.parse('http://www.prh.noaa.gov/cphc/gis-cp.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 3956, in parse
    saxparser.parse(source)
  File ".../anaconda3/lib/python3.6/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File ".../anaconda3/lib/python3.6/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File ".../anaconda3/lib/python3.6/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "/tmp/build/80754af9/python_1516124163501/work/Modules/pyexpat.c", line 414, in StartElement
  File ".../anaconda3/lib/python3.6/xml/sax/expatreader.py", line 370, in start_element_ns
    AttributesNSImpl(newattrs, qnames))
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 2031, in startElementNS
    self.unknown_starttag(localname, list(attrsD.items()))
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 666, in unknown_starttag
    return method(attrsD)
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 1500, in _start_gml_point
    self._parse_srs_attrs(attrsD)
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 1496, in _parse_srs_attrs
    context['where']['srsName'] = srsName
  File ".../anaconda3/lib/python3.6/site-packages/feedparser.py", line 356, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'where'
4

0 回答 0