简体   繁体   中英

Tesla api stock price

I am very new to Python and looking for a way to get the current stock price of TESLA. I have this program but it prints out way too much. I am running python 3 connecting to the school computer via Linux. I can not install Pandas, pip requests or conda because I am not authorized. I even tried sudo. I was hoping to find an api something like this: http://api.bart.gov/api/route.aspx ? but for tesla. I appreciate any help I can get. At this point ucllib seems to work getting the url.

import urllib.request, urllib.parse
params = { "key": "MW9S-E7SL-26DU-VV8V", "cmd": "routes" }
url = "https://finance.yahoo.com/quote/TSLA/history?period1=1436486400&period2=1594339200&interval=1d&filter=history&frequency=1d" + urllib.parse.urlencode(params)
with urllib.request.urlopen(url) as result:
  print(result.read())

Use https://query2.finance.yahoo.com/v10/finance/quoteSummary/tsla?modules=price

import urllib.request, json
resp = urllib.request.urlopen('https://query2.finance.yahoo.com/v10/finance/quoteSummary/tsla?modules=price')
data = json.loads(resp.read())
price = data['quoteSummary']['result'][0]['price']['regularMarketPrice']['raw']
print(price)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM