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)))
供参考