zoukankan      html  css  js  c++  java
  • 实时获取雪球某单只股票数据

    import requests
    
    Cookie = 'xxxxx'
    UserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
    
    headers = {
        'Cookie': Cookie,
        'User-Agent': UserAgent
    }
    for code in ('SZ002013', 'SZ002435'):
        r = requests.get('https://stock.xueqiu.com/v5/stock/quote.json?symbol='+code+'&extend=detail', headers=headers).json()
        rdata = r.get('data').get('quote')
        result = {}
        result['name'] = rdata.get('name')
        result['last_close'] = rdata.get('last_close')
        result['current'] = rdata.get('current')
        result['high'] = rdata.get('high')
        result['low'] = rdata.get('low')
        print(result)

     结果如下

    {'name': '中航机电', 'last_close': 9.9, 'current': 10.46, 'high': 10.5, 'low': 9.91}
    {'name': '长江健康', 'last_close': 6.0, 'current': 6.08, 'high': 6.29, 'low': 5.64}

    整理到一个Python文件中,想看了就执行一下。

    从此又可以愉快的摸鱼了。。。

    注意:Cookie字段,自己登录上雪球,从浏览器中获取,具体获取方法,自行百度。。。

    供参考

    ================================

    优化一下如下:

    只需要输入持有的股数代码和股数,自动计算个股盈亏和当日总盈亏

    import requests
    import time
    
    Cookie = 'xxxxxx'
    UserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
    
    headers = {
        'Cookie': Cookie,
        'User-Agent': UserAgent
    }
    
    # 输入持有的票的代码和股数
    codes = {
        "SZ002013": 900,
        "SZ002435": 1400
    }
    
    print('-'*100)
    sumall = {}
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    
    for code in codes.keys():
        r = requests.get('https://stock.xueqiu.com/v5/stock/quote.json?symbol='+code+'&extend=detail', headers=headers).json()
        rdata = r.get('data').get('quote')
        result = {}
        result['code'] = rdata.get('code')
    #    result['name'] = rdata.get('name')
        result['last_close'] = rdata.get('last_close')
        result['current'] = rdata.get('current')
        result['high'] = rdata.get('high')
        result['low'] = rdata.get('low')
    
        sumall[code] = (result['current'] - result['last_close']) * codes.get(code)
        print(result, ' ', str(round(sumall[code], 2)))
    
    print('Today: ', str(round(sum(sumall.values()), 2)))

    供参考

  • 相关阅读:
    Animate.css 一款强大的预设css3动画库
    关于js返回上一页的实现方法
    jquery判断字符串中是否包含特定字符的方法总结
    去掉select在苹果手机上的原生样式
    html5中如何去掉input type date默认样式
    JS和jQuery中ul li遍历获取对应的下角标
    滚动一定的高度底色递增
    喵哈哈村的狼人杀大战(5)
    喵哈哈村的狼人杀大战(2)
    One Card Poker
  • 原文地址:https://www.cnblogs.com/zhzhang/p/15092660.html
Copyright © 2011-2022 走看看