使用feedparser.py时发生意外错误

时间:2018-08-31 17:24:53

标签: python python-3.x rss feedparser noaa

我在使用https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf模块解析国家飓风中心的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

但是,当我尝试从Central Pacific Hurricane Center读取表面上类似的提要时,会产生KeyError:

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

这是feedparser的错误吗? CPHC的饲料是否变形?有没有我忘记指定的选项?看来麻烦在于没有一个名为“ 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'

0 个答案:

没有答案