用Python爬虫简单抓取股票数据

  • A DEMO Code write by 鹏鹏哥哥

In [1]:

import requests
import threading

In [2]:

def display_info(code):
    url = 'http://hq.sinajs.cn/list=' + code
    response = requests.get(url).text
    print(response)

In [3]:

def single_thread(codes):
    for code in codes:
        code = code.strip()
        display_info(code)

In [4]:

def multi_thread(tasks):
    # 用列表生成线程
    threads = [threading.Thread(target=single_thread, args = (codes,)) for codes in tasks]
    # 启动线程
    for t in threads:
        t.start()
    # 等待线程结束
    for t in threads:
        t.join()

In [6]:

if __name__ == '__main__':
    codes = ['sh600519', 'sh600520', 'sh600521', 'sh600522', 'sh600523', 'sh600524']
    # 计算线程工作量,就是每个线程处理几个股票的意思
    thread_len = int(len(codes) / 4)
    # 定义开启多线程
    t1 = codes[0: thread_len]
    t2 = codes[thread_len: thread_len * 2]
    t3 = codes[thread_len * 2: thread_len * 3]
    t4 = codes[thread_len * 3: thread_len * 4]
    
    # 开启多线程
    multi_thread([t1, t2, t3, t4])
var hq_str_sh600520="文一科 技,12.690,12.860,13.160,13.220,12.690,13.140,13.160,1451501,18772231.000,2400,13.140,3200,13.130,3000,13.110,34000,13.100,5800,13.070,5600,13.160,15600,13.170,11300,13.180,3600,13.190,6300,13.200,2018-11-30,15:00:00,00";

var hq_str_sh600519="贵州茅台,557.000,551.600,565.000,568.890,553.000,565.000,565.510,4901046,2762808219.000,7300,565.000,100,564.990,200,564.980,200,564.900,100,564.830,300,565.510,600,565.600,100,565.690,100,565.800,800,565.900,2018-11-30,15:00:00,00";

var hq_str_sh600522="中天科技,7.660,7.690,7.760,7.760,7.530,7.740,7.760,23377275,178878093.000,85800,7.740,121700,7.730,168074,7.720,15300,7.710,22100,7.700,80821,7.760,113300,7.770,168300,7.780,93700,7.790,131200,7.800,2018-11-30,15:00:00,00";

var hq_str_sh600521="华海药业,13.410,13.460,13.710,13.820,13.340,13.710,13.720,13269276,180933323.000,49580,13.710,85500,13.700,3340,13.690,46200,13.680,17700,13.670,6500,13.720,21505,13.730,14200,13.740,38800,13.750,12000,13.760,2018-11-30,15:00:00,00";

In [ ]:

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值