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

编程入门 行业动态 更新时间:2024-10-10 17:32:24

用Python<a href=https://www.elefans.com/category/jswz/34/1770264.html style=爬虫简单抓取股票数据"/>

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

  • A DEMO Code write by 鹏鹏哥哥

In [1]:

import requests
import threading

In [2]:

def display_info(code):url = '=' + coderesponse = requests.get(url).textprint(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 [ ]:

 

更多推荐

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

本文发布于:2024-03-13 22:21:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1734996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:爬虫   简单   股票   数据   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!