这是输出。我只想要“ MMM”,下一个是“ ABT”。 ['MMM','ABT','ABBV','ABMD','ACN','ATVI','ADBE','AMD'] 追踪市盈率:17.85 股本回报率:54.34% 收入:32.35B 季度收入增长:-5.00% ['MMM','ABT','ABBV','ABMD','ACN','ATVI','ADBE','AMD'] 追踪市盈率:55.03 股本回报率:8.28% 收入:30.72B 季度收入增长:2.00%
我试图使其打印(stock_list [each_stock]),但它给出了错误消息。
此外,即使根据雅虎财务,“ MMM”同时满足条件1和3,它也会始终打印else语句(没有股票),因此它应该打印“ MMM”的代码和基本面。
def scrape(stock_list, interested, technicals):
condition_1 = float(technicals.get('Return on Equity',0)) > 0
condition_2 = float(technicals.get('Trailing P/E',0)) > 2
condition_3 = float(technicals.get('Price/Book (mrq)',0)) <11
if (condition_1 and condition_3)==True:
for each_stock in stock_list:
technicals = scrape_yahoo(each_stock)
print(stock_list)
for ind in interested:
print(ind + ": "+ technicals[ind])
print("------")
time.sleep(1)
else:
print('No stocks found') # Use delay to avoid getting flagged as bot
return technicals
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()
def scrape(stock_list, interested, technicals):
condition_1 = float(technicals.get('Return on Equity',0)) > 0
condition_2 = float(technicals.get('Trailing P/E',0)) > 2
condition_3 = float(technicals.get('Price/Book (mrq)',0)) <11
if (condition_1 and condition_3)==False:
for each_stock in stock_list:
technicals = scrape_yahoo(each_stock)
print(stock_list)
for ind in interested:
print(ind + ": "+ technicals[ind])
print("------")
time.sleep(1)
else:
print('No stocks found') # Use delay to avoid getting flagged as bot
return technicals
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()```