I am using the replace function to get rid of the percentage so to can more easily be turned into an integer. In addition, I want to use the replace function in case a N/A appears in the data.
This is for a stock screener I am trying to develop, where it goes through a list of stocks and gives me the remaining ones based off of my criteria.
def scrape(stock_list, interested, technicals):
condition_1 = float(technicals.get('Return on Equity',0).replace("%","")) > 0
condition_2 = float(technicals.get('Trailing P/E',0).replace("N/A","")) > 20
for each_stock in stock_list:
technicals = scrape_yahoo(each_stock)
if condition_1 and condition_2:
print(each_stock)
for ind in interested:
print(ind + ": "+ technicals[ind])
print("------")
time.sleep(1) # 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()
AttributeError: 'int' object has no attribute 'replace'
technicals.get('Return on Equity',0).replace("%","")
如果technicals
不包含“股本回报率”,则使用整数0作为默认值,并且不能对整数调用replace()。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.