2017-10-10 95 views
-1

我可以在我的URL中獲得一個股票代碼...但是如何創建列表並通過URL進行循環。請參閱失敗的嘗試...這是一個我正在擺弄的tweepy項目。主要擔心通過多個網址。通過列表中的python url的循環變量

ticker=["AAPL","XOM"] 
For i < len(ticker): 


    responeData = requests.get("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol="+str(ticker[i])+"&apikey=XXXXXX") 
    symbol = str(responeData.json()['Meta Data']['2. Symbol']) 
    refresh = str(responeData.json()['Meta Data']['3. Last Refreshed']) 
    checkclose = str(responeData.json()['Time Series (Daily)']) 
    close=str(responeData.json()['Time Series (Daily)'][refresh]['4. close']) 


    api.update_status(status=symbol+' '+refresh+' Close Price: $'+close) 
+1

那麼,首先,你的for循環在語法上是無效的...... – kindall

回答

0

您可以使用for循環迭代您的列表。

tickers=["AAPL","XOM"] 
for ticker in tickers: 

    responeData = requests.get("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol="+ticker+"&apikey=XXXXXX") 
    symbol = str(responeData.json()['Meta Data']['2. Symbol']) 
    refresh = str(responeData.json()['Meta Data']['3. Last Refreshed']) 
    checkclose = str(responeData.json()['Time Series (Daily)']) 
    close=str(responeData.json()['Time Series (Daily)'][refresh]['4. close']) 

    api.update_status(status=symbol+' '+refresh+' Close Price: $'+close)