大萨达撒多

sad撒多撒

# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import lxml
import json
import re
import time
import tushare as ts
import pandas as pd

def EMydSpider(current):
    # 抓取东财个股盘口异动数据:http://quote.eastmoney.com/changes
    ydData = []
    chg_date = current
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3676.400 QQBrowser/10.5.3738.400"}
    url = "http://push2ex.eastmoney.com/getAllStockChanges?type=8201,8202,8193,4,32,64,8207,8209,8211,8213,8215,8204,8203,8194,8,16,128,8208,8210,8212,8214,8216"
    for page in range(200):
        param = {"pageindex": page,"pagesize": '64',"ut": '7eea3edcaed734bea9cbfc24409ed989',"dpt": 'wzchanges'}
        html = json.loads(requests.get(url=url, params=param, headers=header).text)
        if html['data'] is None:
            print("东方财富:共爬取%d页数据" % page)
            print("东方财富:个股盘口异动数据已抓取完成")
            break
        else:
            allstock = html['data']['allstock']
            for stock in allstock:
                stk_code = stock['c']
                stk_name = stock['n']
                chg_time = stock['tm']
                chg_type = stock['t']
                chg_value = stock['i']

                ydData.append([stk_code, stk_name, chg_date, chg_time, chg_type, chg_value])
                print(ydData)

猜你喜欢

转载自www.cnblogs.com/Iceredtea/p/11901060.html