I am interested in extracting historical prices from this link: https://pakstockexchange.com/stock2/index_new.php?section=research&page=show_price_table_new&symbol=KEL
To do so I am using the following code
import requests
import pandas as pd
import time as t
t0=t.time()
symbols =[
'HMIM',
'CWSM','DSIL','RAVT','PIBTL','PICT','PNSC','ASL',
'DSL','ISL','CSAP','MUGHAL','DKL','ASTL','INIL']
for symbol in symbols:
header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"
}
r = requests.get('https://pakstockexchange.com/stock2/index_new.php?section=research&page=show_price_table_new&symbol={}'.format(str(symbol)), headers=header)
dfs = pd.read_html(r.text)
df=dfs[6]
df=df.ix[2: , ]
df.columns=['Date','Open','High','Low','Close','Volume']
df.set_index('Date', inplace=True)
df.to_csv('/home/furqan/Desktop/python_data/{}.csv'.format(str(symbol)),columns=['Open','High','Low','Close','Volume'],
index_label=['Date'])
print(symbol)
t1=t.time()
print('exec time is ', t1-t0, 'seconds')
Above code extracts data from the link converts it into pandas data frame and saves it.
Problem is that it takes a lot of time and is not efficient with greater number of symbols. Can anyone suggest any other way to achieve the above result in an efficient way.
Moreover, is there any other programming language that would do the same job but in a less time.
requests-futures?