preface

By the end of 2019, the number of China’s stock investors is 159,752,400 households, so many investors are keen on stock speculation, first of all, put aside the technology of stock speculation, so much stock data is not very difficult to find, find after looking at the dense data is not the head is big?

Today, I will take you to climb the stock data of snowball platform and realize data visualization

Take a look at the renderings first

! [](https://p9-tt-ipv6.byteimg.com/large/pgc-image/e85d2682ccad4f2b83716afc5e0aff66)

Basic Environment Configuration

  • Python 3.6
  • pycharm
  • requests
  • csv
  • time

The target address

https://xueqiu.com/hq
Copy the code
! [](https://p6-tt-ipv6.byteimg.com/large/pgc-image/8017b82192b047589bf59b2929a5c0bb)

The crawler code

The request page

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() #Copy the code

Analytical data

data_list = html_data['data']['list'] for i in data_list: Dit = {} dit [' stock code] = [' symbol '] I dit [' stock name '] = [' name '] I dit [' current price] = [' current '] I dit [' rise and fall of '] = [' CHG] I dit [' price / %] = [' percent] I dit [' year-to-date / %] = [' current_year_percent] I dit [' volume '] = [' volume '] I dit [' turnover '] = [' amount '] I dit [' turnover rate / %] = [' turnover_rate] I dit [' p/e TTM] = [' pe_ttm] I dit [' dividend yield / %] = [' dividend_yield] I dit [' market value '] = [' market_capital] I print(dit)Copy the code

Save the data

Import CSV f = open(' stock data.csv ', mode='a', encoding=' UTF-8-sig ', newline='') csv_writer = csv.dictwriter (f, encoding=' utF-8-sig ', newline='') Fieldnames = [' stock code ', 'stock name', 'current price', 'or the forehead', 'price / %', 'year-to-date / %', 'volume', 'turnover', 'turnover rate / %', 'p/e TTM', 'dividend yield / %' ]) csv_writer.writeHeader () csv_writer.writerow(dit) f.close()Copy the code
! [](https://p9-tt-ipv6.byteimg.com/large/pgc-image/e9dfc35444044feeb4c9519f6b4c7b58)
! [](https://p6-tt-ipv6.byteimg.com/large/pgc-image/b2be12cc1e3e4839a617afdf115549e8)

Data analysis code

C = (Bar().add_xaxis(list(df2[' 名 字 '].values)).add_yaxis(" 名 字 ", List (df2[' Volume '].values).set_global_opts(title_opts= opts.titleopts (title=" Volume chart - Volume chart"), datazoom_opts=opts.DataZoomOpts(), ) .render("data.html") )Copy the code
! [](https://p1-tt-ipv6.byteimg.com/large/pgc-image/d59f3102a2214296ae54d86eaa0484ad)

Have you bought any stocks? I did buy some funds!

Complete project code acquisitionPoint it