时间:2020-09-25来源:www.pcxitongcheng.com作者:电脑系统城
前言
截止2019年年底我国股票投资者数量为15975.24万户, 如此多的股民热衷于炒股,首先抛开炒股技术不说, 那么多股票数据是不是非常难找, 找到之后是不是看着密密麻麻的数据是不是头都大了?
今天带大家爬取雪球平台的股票数据, 并且实现数据可视化
先看下效果图
基本环境配置
目标地址
https://xueqiu.com/hq
爬虫代码
请求网页
import requests url = 'https://xueqiu.com/service/v5/stock/screener/quote/list' response = requests.get(url=url, params=params, headers=headers, cookies=cookies) html_data = response.json() #想要完整代码的同学请关注微信公众号:松鼠爱吃饼干 #发送信息‘股票’即可获取
解析数据
data_list = html_data['data']['list'] for i in data_list: dit = {} dit['股票代码'] = i['symbol'] dit['股票名字'] = i['name'] dit['当前价'] = i['current'] dit['涨跌额'] = i['chg'] dit['涨跌幅/%'] = i['percent'] dit['年初至今/%'] = i['current_year_percent'] dit['成交量'] = i['volume'] dit['成交额'] = i['amount'] dit['换手率/%'] = i['turnover_rate'] dit['市盈率TTM'] = i['pe_ttm'] dit['股息率/%'] = i['dividend_yield'] dit['市值'] = i['market_capital'] print(dit)
保存数据
import csv f = open('股票数据.csv', mode='a', encoding='utf-8-sig', newline='') csv_writer = csv.DictWriter(f, fieldnames=['股票代码', '股票名字', '当前价', '涨跌额', '涨跌幅/%', '年初至今/%', '成交量', '成交额', '换手率/%', '市盈率TTM', '股息率/%', '市值']) csv_writer.writeheader() csv_writer.writerow(dit) f.close()
数据分析代码
c = ( Bar() .add_xaxis(list(df2['股票名称'].values)) .add_yaxis("股票成交量情况", list(df2['成交量'].values)) .set_global_opts( title_opts=opts.TitleOpts(title="成交量图表 - Volume chart"), datazoom_opts=opts.DataZoomOpts(), ) .render("data.html") )
2023-03-17
python flask项目打包成docker镜像发布的过程2023-03-17
python调试模块ipdb详解2023-03-17
python使用openai生成图像的超详细教程python cron定时任务触发接口自动化巡检 apscheduler报错:Run time of job …… next run at: ……)” was missed by misfire_grace_time参数 找到任务超时的根本原因...
2023-03-15