# 从网上获取股票交易历史数据
# url = 'http://quotes.money.163.com/service/chddata.html?code=1000001&start=19910401&end=19910409'
# url += '&fields=LCLOSE;TOPEN;HIGH;LOW;TCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP'
import requests
import pandas as pd
import matplotlib.pyplot as plt
stock_code='1000020'
start_date='19990809'
end_date='20190809'
url = 'http://quotes.money.163.com/service/chddata.html?code={}&start={}&end={}'.format(stock_code,start_date,end_date)
#从网上获取数据
online_data=requests.get(url)
csv_file_name='stock_{}.csv'.format(stock_code)
#将数据保存到本地csv文件
with open(csv_file_name,"wb") as f:
f.write(online_data.content)
stock_data=pd.read_csv(csv_file_name,encoding='gb2312')
stock_data=stock_data.sort_values(by = ["日期"],ascending = [True],i
python获取网上股市信息示例
最新推荐文章于 2024-08-27 11:09:57 发布
本文通过Python演示如何从互联网获取实时股市信息,包括股票价格、交易量等关键数据,帮助读者理解网络金融数据的抓取和处理过程。
摘要由CSDN通过智能技术生成