How to download historical stock closing price of the stock's closing price history Download method

 

I do not want to write code, then turn to the article download a ready tool at the bottom.

In addition to obtaining historical closing price of the stock by a third-party interfaces, we also can get their own way through the crawl.

We have a financial Web site, for example, the stock's closing price history is this:
How to download historical closing price of the stock
From the picture can be seen, is in accordance with the stock closing price in history - quarter of the way of loading, linking each quarter of each year is not the same .

Simple out about:

  1. According to quarterly historical links to splice out closing price. For example, links the first quarter of 2020 and second quarter of 2020 is not the same, but the only link these two figures are not the same, the other is the same.
  2. Parse out the daily closing price history
  3. Save to Excel or a database
import requests,re,pandas

# 这里年月都可以用datatime来实现,这里就直接写出来了。
year = [2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020]
month = [1,2,3,4]

base_url = 'https://www.baidu.com/' # 假设要抓取的网站是百度

one_list = []
arry_list = []

for y in year:
	for m in month:
		y_m =f'{y}-{m}'
		response = requests.get(f'{base_url}?{y_m}') # 这里获取到了2010年1季度的源码,依次循环会获取到2020年4季度。
		close_price = re.findall('(\d+)',response.text) # 这里通过正则解析除了股票的历史收盘价
		one_list.append(close_price)
		arry_list.append(one_list)

df = pandas.DataFrame(a, columns=['open_price', 'close_price', 'vol']) 
wt = ExcelWriter(path) # path 是文件的保存路径,要精确到文件名
df.to_excel(wt, sheet_name='如何下载股票的历史收盘价' , index=False)

We can put more of a stock's closing price history is saved to Excel, or relatively simple.

I do not want to write directly to the following two-dimensional code scan code, self-service download, no restrictions, 2 seconds to complete.
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/zdnyp/p/12174674.html