webserviceを使用して、結果セットをループしようとしています。Webサービスの結果のループが機能しない
総合ランク:537316レベル:1419 XPの場合:6407333
残りを通じてサイクルを停止していないように見える、それはこの場合のみである最初の結果を私に戻っていますいくつかの理由 リストのリストの中の結果のうち、grab_api
の機能からstat_list
までです。
stat_list
は、リスト内に数字の文字列が入ったリストです。あなたがhiscore == 0
代わりのhiscore = 0
をしているあなたのelse
ブロックで
import urllib2
import re
def grab_api():
stat_list = []
response = urllib2.urlopen('http://services.runescape.com/m=hiscore/index_lite.ws?player=taroboxx')
html = response.read()
stat_list.append(re.split(r"[,\n]", html))
return stat_list
def check_score(hiscore_html):
stats = ["Overall", "Attack", "Defence", "Strength", "Constitution", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecrafting", "Hunter", "Construction", "Summoning", "Dungeoneering", "Divination"]
hiscore = 0
stat = 0
for i in hiscore_html[0]:
if hiscore == 0:
print stats[stat],
print "Rank:", i,
stat += 1
hiscore += 1
elif hiscore == 1:
print "Level:", i,
hiscore += 1
elif hiscore == 2:
print "Xp:", i
hiscore += 1
else:
hiscore == 0
check_score(grab_api())
opps私は実際にそこで変更されました。コードのその部分が変更されたとしても、最初の3回のインターラクションでのみ結果が生成されます。私はそれを持っていた:for hiscore_html [0] –
更新された答えを見てください。 – DeepSpace
あなたは天才です –