You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
#!/usr/bin/env python3
|
|
"""
|
|
查询深证成指
|
|
"""
|
|
|
|
import urllib.request
|
|
import socket
|
|
|
|
# 设置超时
|
|
socket.setdefaulttimeout(10)
|
|
|
|
print("正在查询深证成指...")
|
|
|
|
# 深证成指 399001
|
|
try:
|
|
url = "http://qt.gtimg.cn/q=sz399001"
|
|
print(f"正在访问: {url}")
|
|
|
|
with urllib.request.urlopen(url) as f:
|
|
content = f.read().decode('gbk')
|
|
print(f"\n✅ 获取成功!")
|
|
|
|
# 解析腾讯格式
|
|
if 'v_sz399001' in content:
|
|
data_part = content.split('"')[1]
|
|
parts = data_part.split('~')
|
|
|
|
name = parts[1]
|
|
code = parts[2]
|
|
current = parts[3]
|
|
prev_close = parts[4]
|
|
open_price = parts[5]
|
|
volume = parts[6]
|
|
amount = parts[7]
|
|
high = parts[33]
|
|
low = parts[34]
|
|
|
|
print(f"\n📊 {name} ({code})")
|
|
print(f" 当前: {current}")
|
|
print(f" 今开: {open_price}")
|
|
print(f" 昨收: {prev_close}")
|
|
print(f" 最高: {high}")
|
|
print(f" 最低: {low}")
|
|
print(f" 成交量: {volume}")
|
|
print(f" 成交额: {amount}")
|
|
|
|
# 计算涨跌幅
|
|
try:
|
|
curr = float(current)
|
|
prev = float(prev_close)
|
|
change = curr - prev
|
|
pct = (change / prev) * 100
|
|
|
|
if change > 0:
|
|
print(f" 📈 涨跌: +{change:.2f} (+{pct:.2f}%)")
|
|
elif change < 0:
|
|
print(f" 📉 涨跌: {change:.2f} ({pct:.2f}%)")
|
|
else:
|
|
print(f" 涨跌: {change:.2f} (0.00%)")
|
|
except:
|
|
pass
|
|
|
|
except Exception as e:
|
|
print(f"❌ 查询失败: {e}")
|
|
|