2017-07-30 85 views
0

我期待迴路印刷同義詞對每個項目從我的名單從循環使用Python unirest列表

myList = ["First", "Second", "Third"] 

嘗試沒有成功幾個循環的方法,請大家幫忙

手動打印出來1通過1命令是

response = unirest.get("https://wordsapiv1.p.mashape.com/words/first/synonyms", headers={ "X-Mashape-Key": "**MY -Mashape-Key", "Accept": "application/json" }) 

response.body < ===這將打印字同義詞 「第一」

如何循環打印我的列表中的所有單詞的正文? 感謝

+0

你可以顯示示例json輸出嗎?我們沒有這個網站的任何API密鑰。 – aristotll

+0

我可以私下分享你一個私人密鑰,以測試你是否想要,我真的很喜歡這個。謝謝 – totheM

回答

0

試試這個

for word in myList 
    response = unirest.get("https://wordsapiv1.p.mashape.com/words/" + word + "/synonyms", headers={ "X-Mashape-Key": "API_KEY", "Accept": "application/json" }) 
    print response.body 

我不知道Python,但其文檔,似乎它應該工作。

+0

這是我嘗試的第一個命令,但它說TypeError:不能連接'str'和'list'對象 – totheM

+0

@totheM錯誤意味着'word'是一個列表對象。所以你應該檢查'myList'是否是列表的列表。 – aristotll

+0

這主要是我的錯誤嘗試unirest.post而不是unirest.get – totheM