49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
#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("投资建议:安全,股债策略10:0")
|
||
if 2.2<=ad<2.5:
|
||
print("投资建议:较为安全,股债策略7:3")
|
||
if 2<=ad<2.2:
|
||
print("投资建议:谨慎乐观,股债策略6:4")
|
||
if 1.8<=ad<2:
|
||
print("投资建议:普通,股债策略5:5")
|
||
if 1.55<=ad<1.8:
|
||
print("投资建议:有风险,股债策略4:6")
|
||
if ad<1.55:
|
||
print("投资建议:赶紧跑")
|
||
|