我如何创建一个For循环来创建多个URL地址(仅更改一个)?

问题描述 投票:0回答:1

这是我的代码,用于为Yahoo Finance与特定公司(在本例中为Microsoft)创建URL链接。

index = 'MSFT'
url_is = 'https://finance.yahoo.com/quote/' + index + '/financials?p=' + index

我如何为具有不同股票代码的多个公司(例如index = ['MSFT','AAPL','V']创建文件库)

非常感谢

python yahoo-finance
1个回答
0
投票

尝试一下:

index = ['MSFT', 'AAPL', 'V']
for company in index:
    url_is = 'https://finance.yahoo.com/quote/' + company + '/financials?p=' + company
    print(url_is)

如果您希望将结果URL存储在列表中,请执行以下操作:

my_list = []
for company in index:
    url_is = 'https://finance.yahoo.com/quote/' + company + '/financials?p=' + company
    my_list.append(url_is)
© www.soinside.com 2019 - 2024. All rights reserved.