基本环境配置
python 3.6 pycharm requests csv time相关模块pip安装即可
目标网页
分析网页
一切的一切都在图里
找到数据了,直接请求网页,解析数据,保存数据
请求网页
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()
您可能感兴趣的文章:Python爬取股票信息,并可视化数据的示例python多线程+代理池爬取天天基金网、股票数据过程解析使用python爬虫实现网络股票信息爬取的demo详解python爬取弹幕与数据分析Python爬虫过程解析之多线程获取小米应用商店数据python爬虫中PhantomJS加载页面的实例方法python cookie反爬处理的实现基于Python爬取搜狐证券股票过程解析