非常非常新的Python的,我瞭解的情況是我剛剛建在最後幾個小時:重複輸出
from sys import argv
import requests
import xml.etree.ElementTree as ET
script, gameid = argv
game = requests.get("http://boardgamegeek.com/xmlapi/game/" + (gameid))
r = game.text
root = ET.fromstring(r)
boardgame = root.findall('boardgame')
for b in boardgame:
name = b.find('name').text
year = b.find('yearpublished').text
mech = b.find('boardgamemechanic').text
cat = b.find('boardgamecategory').text
print (name,",",year,",",mech,",",cat)
這是做什麼我希望它這是根據用戶輸入給我的上述四條信息。
我想知道的是,如果可以運行此腳本n次,其中n是在cmd行輸入的參數數量?
輸出類似於如下:
C:\Python>bgg.py 822
Carcassonne , 2000 , Area Control/Area Influence , City Building
C:\Python>bgg.py 25417
BattleLore , 2006 , Campaign/Battle Card Driven , Fantasy
我想是如果我能得到類似下面:
C:\Python>bgg.py 822 25417
Carcassonne , 2000 , Area Control/Area Influence , City Building
BattleLore , 2006 , Campaign/Battle Card Driven , Fantasy
乾杯
將您的代碼移入循環。你能從該網站一次查詢多個ID嗎? –
我會將哪些部分放入循環中,而且我不確定是否可以一次查詢多個部分? – Accendi