我制作了一个股票筛选器,该筛选器给出了符合我的条件的股票技术,最后,我希望它打印出符合我的条件的简要股票清单。我尝试使用附加功能,但它只打印一只股票,相反,我希望它打印要打印的每只股票的股票行情,例如“ mmm”,...
当前输出如下所示。 MMM 尾随市盈率:17.61 股本回报率:54.34% 收入:32.35B 季度收入增长:-5.00%
def scrape(stock_list, interested, technicals):
for each_stock in stock_list:
technicals = scrape_yahoo(each_stock)
condition_1 = float(technicals.get('Return on Equity',0).replace('%','').replace('N/A','-100')) > 25
condition_2 = float(technicals.get('Trailing P/E',0).replace('N/A','')) > 15
condition_3 = float(technicals.get('Price/Book (mrq)',0)) <15
if (condition_1 and condition_2)==True:
print(each_stock)
SuggestedStocks = []
SuggestedStocks.append(each_stock)
for ind in interested:
print(ind + ": "+ technicals[ind])
print("------")
time.sleep(1) # Use delay to avoid getting flagged as bot
#return technicals
print(SuggestedStocks)
def main():
stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD']
interested = ['Trailing P/E', 'Return on Equity', 'Revenue', 'Quarterly Revenue Growth']
technicals = {}
tech = scrape(stock_list, interested, technicals)
print(tech)
main()
它只打印满足我的条件的最后一支股票的代码:ADBE。
答案 0 :(得分:1)
这是因为您在每个循环SuggestedStocks = []
中都重置了建议的库存,因此您应该在循环之外进行初始化。