data/method/股市/bonus.py

49 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#coding=utf-8
from operator import index
from pkgutil import ImpImporter
import requests
import re
import datetime
current_time = datetime.datetime.now()
print("当前时间: " + str(current_time))
url="https://www.kancaibao.com/ep"
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55"
} #以字典的形式设置请求头,处理反爬
resp=requests.get(url,headers=headers)
resp.encoding = resp.apparent_encoding #设置编码格式
pattern = re.compile(r'\'date_0\'>(\w*)?<.*gzclose_0\'>(\w\W\w*).*ratemv_0\'>(\w\W\w{4}).*rategz_0\'>(\w\W\w{2})')
s = str(resp.text)
ret = re.search(pattern, s)
a=float(ret.group(2))*100
c = str(round(a,2))+ '%'
a=float(ret.group(3))*100
b = str(round(a,3))+ '%'
#print(ret.group(3))
#print(ret.group(4))
print("所获取的信息如下")
print('日期:', ret.group(1))
print('股债比', ret.group(4))
print('国债收益率',c)
print('平均股权收益率',b)
ad = float(ret.group(4))
if ad>=2.5:
print("投资建议安全股债策略100")
if 2.2<=ad<2.5:
print("投资建议较为安全股债策略73")
if 2<=ad<2.2:
print("投资建议谨慎乐观股债策略64")
if 1.8<=ad<2:
print("投资建议普通股债策略55")
if 1.55<=ad<1.8:
print("投资建议有风险股债策略46")
if ad<1.55:
print("投资建议:赶紧跑")