나는 포럼에서이 스크립트를 가지고 있으며 나는이에 대한 답변 주위를 검색 한구문 분석 XML 응답 : 범위 에러 중 목록 지수는
Traceback (most recent call last):
File "test.py", line 42, in <module> main()
File "test.py", line 28, in main
bot_response = objektid[0].toxml()
IndexError: list index out of range
다음과 같은 오류와 함께 올라오고 계속하지만, 내가 관련이 없습니다 내 코드에 대한 대답, 어쩌면 내가 파이썬과 같은 멍청한 놈인 것 때문에.
스크립트는 다음과 같습니다.
objektid = dom.getElementsByTagName('that')
그렇게 목록이 비어 :
#!/usr/bin/python -tt
# Have a conversation with a PandaBot AI
# Author A.Roots
import urllib, urllib2
import sys
from xml.dom import minidom
from xml.sax.saxutils import unescape
def main():
human_input = raw_input('You: ')
if human_input == 'exit':
sys.exit(0)
base_url = 'http://www.pandorabots.com/pandora/talk-xml'
data = urllib.urlencode([('botid', 'ebbf27804e3458c5'), ('input', human_input)])
# Submit POST data and download response XML
req = urllib2.Request(base_url)
fd = urllib2.urlopen(req, data)
# Take Bot's response out of XML
xmlFile = fd.read()
dom = minidom.parseString(xmlFile)
objektid = dom.getElementsByTagName('that')
bot_response = objektid[0].toxml()
bot_response = bot_response[6:]
bot_response = bot_response[:-7]
# Some nasty unescaping
bot_response = unescape(bot_response, {"&apos;": "'", "&quot;": '"'})
print 'Getter:',str(bot_response)
# Repeat until terminated
while 1:
main()
if __name__ == '__main__':
print 'Hi. You can now talk to Getter. Type "exit" when done.'
main()
이에 대한 당신의 도움이 크게
시도처럼 뭔가를 할 주위에
는 objektid'가'print'ing'얻으려면 - 당신이 빈 목록을 얻고있는 것 같습니다, 그래서 마티의 @ 볼 때 아무것도 인덱스 0 – thegrinner