How to Scrape and Batch-Download Stock Minute Data from Eastmoney with Python

This article walks through the step-by-step process of extracting individual and batch stock minute-level data from Eastmoney using Python, covering URL analysis, parameter discovery, handling pagination, constructing CSV output, and extending the script to fetch arbitrary dates via cookie manipulation.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Scrape and Batch-Download Stock Minute Data from Eastmoney with Python

In this tutorial, the author demonstrates how to retrieve minute‑level trading data for individual stocks from the Eastmoney website using Python.

1. Data collection

First, open a stock’s detail page, click “more minute‑trade”, and observe that the data is loaded via a GET request returning JSON wrapped in a jQuery callback. The pageindex parameter controls pagination.

The following script fetches the minute data for a single stock and writes it to a CSV file.

import requests
import csv
with open('688103.csv','a',newline='') as f:
    writer = csv.writer(f)
    writer.writerow(['时间','成交价','手数'])
    for page in range(27):
        params = (
            ('pagesize','144'),
            ('ut','7eea3edcaed734bea9cbfc24409ed989'),
            ('dpt','wzfscj'),
            ('cb','jQuery1124029337350072397084_1631343037828'),
            ('pageindex',str(page)),
            ('id','6009051'),
            ('sort','1'),
            ('ft','1'),
            ('code','688103'),
            ('market','1'),
            ('_','1631343037827'),
        )
        response = requests.get('http://push2ex.eastmoney.com/getStockFenShi', params=params, verify=False)
        for i in eval(response.text[43:-2])['data']['data']:
            with open('688103.csv','a',newline='') as f:
                writer = csv.writer(f)
                # time parsing logic …
                if i['bs'] == 4:
                    a = '--'
                elif i['bs'] == 2:
                    a = '买入'
                elif i['bs'] == 1:
                    a = '卖出'

2. Batch scraping

To scrape multiple stocks, the script is extended to iterate over a list of stock codes, adjusting the “id” and “code” parameters accordingly.

gupiao_code = ['301073']
for code in gupiao_code:
    with open(f'{code}.csv','a',newline='') as f:
        writer = csv.writer(f)
        writer.writerow(['时间','成交价','手数','买入/卖出'])
    try:
        for page in range(40):
            params = (
                ('pagesize','144'),
                ('ut','7eea3edcaed734bea9cbfc24409ed989'),
                ('dpt','wzfscj'),
                ('cb','jQuery112408490604705504154_1633509557420'),
                ('pageindex',str(page)),
                ('id','3010732'),
                ('sort','1'),
                ('ft','1'),
                ('code',code),
                ('market','0'),
                ('_','1633509557478'),
            )
            # request and processing …

3. Fetching data for any date

The date parameter is stored in a cookie named “st_sp”. By modifying this value, the script can retrieve minute data for arbitrary dates.

riqi = input('输入格式如下:xxxx-')
cookies = {
    'st_sp': f'{riqi}%2014%3A57%3A10',
}
# use cookies in the request …

Conclusion

The tutorial provides a complete method to batch‑download stock minute data from Eastmoney.

Eastmoney does not enforce anti‑scraping measures, but respectful intervals are recommended.

The code is for learning purposes only and should not be used for commercial exploitation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Web ScrapingStock DataEastmoney
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.