我使用python庫維基百科來解析數據。當它到達代碼的第二部分時,我會收到頁面錯誤。 Page ErrorsPython Wikipedia庫
import wikipedia
print ("1: Searching Wikipedia for 'List of Lexus vehicles'")
try:
print (wikipedia.page('List of Lexus'))
print ('-' * 60)
except wikipedia.exceptions.DisambiguationError as e:
print (str(e))
print ('+' * 60)
print ('DisambiguationError: The page name is ambiguous')
print
print ("2: Searching Wikipedia for 'List of Lexus (vehicles)'")
print (wikipedia.page('List of Lexus_(vehicles)'))
print
result = wikipedia.page('List of Lexus_(vehicles)').content.encode('UTF8')
print ("3: Result of searching Wikipedia for 'List of Lexus_(vehicles)':")
print (result)
print
lexus_count = result.count('ct','lfa','rx')
print
print ("The Wikipedia page for 'Lexus_(company)' has " + \
"{} occurrences of the word 'Lexus'".format(lexus_count))
print
更新 我能夠解析在數
23 print
24
25 lexus_count = result.count('ct','lfa','rx')
26 print
TypError: slice indices must be integers or None or have an __index__ method
請將您收到的錯誤複製並粘貼到問題中,而不是發佈文字圖像。 – jwodder
當我在維基百科上搜索雷克薩斯(公司)時,結果顯示:'雷克薩斯(公司)「頁面不存在。您可以要求創建它,但請考慮檢查下面的搜索結果,以確定該主題是否已被覆蓋。所以錯誤信息是有道理的 – smoggers