You can check out this gist link for the yahoo finance ticker symbol to name conversion which I made by scraping the yahoo-finance screener page - https://gist.github.com/vipul79321/07a814b850710b0c0f17a1394f0e206c
or alternately you can use this code. Do remember to update the BASE_URL
by creating a suitable screener for your use case -
import request
import json
import time
BASE_URL = "https://in.finance.yahoo.com/screener/unsaved/2af53bef-86ce-40bb-bc6d-941183afd568?offset=OFFSET&count=COUNT"
cnt = 100
offset = 0
flag = 1
temp = 10
name_to_symbol = dict()
while flag > 0:
url = BASE_URL.replace("OFFSET", str(offset))
url = url.replace("COUNT",str(cnt))
offset += cnt
response = requests.get(url)
s = str(response.text)
jsonArrayStart = s.find('"results":{"rows"') + 18
jsonArrayEnd = jsonArrayStart + 1
while s[jsonArrayEnd] != ']':
jsonArrayEnd += 1
jsonArrayString = s[jsonArrayStart: jsonArrayEnd+1]
jsonArray = json.loads(jsonArrayString)
print(len(jsonArray))
if len(jsonArray) != cnt:
flag = 0
for obj in jsonArray:
if 'longName' in obj:
name_to_symbol[obj['symbol']] = obj['longName']
elif 'shortName' in obj:
name_to_symbol[obj['symbol']] = obj['shortName']
else:
name_to_symbol[obj['symbol']] = obj['symbol']
time.sleep(10)