1 Star 1 Fork 1

Dr.wang/FundCalculator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
fund_getter.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
NolanSun 提交于 2018-08-23 10:17 . 2018/8/23
# coding=utf-8
import requests
import time
from bs4 import BeautifulSoup
class FundGetter(object):
def __init__(self, fundcode):
self.fundcode = fundcode
def get_price(self):
while 1:
baseurl = ('http://fund.eastmoney.com/%s.html' % (str(self.fundcode)))
r = requests.get(baseurl)
time.sleep(5) # 避免网速低而加载过慢
content = r.text
soup = BeautifulSoup(content, 'lxml')
divs = soup.find_all(class_='dataNums')
print(divs)
if divs == []or len(divs) != 3:
print('获取失败,记录错误...')
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + 'logging error...')
with open('C:\\Users\\sunhaoran\\Documents\\fund_log.txt', 'a', encoding='UTF-8')as f:
f.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
f.write(str(soup))
f.write('=' * 50)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + 'logged...')
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + '数据获取失败,五分钟后将重试')
time.sleep(300)
else:
break
div = divs[1]
num = div.get_text()
num = str(num)
worth = float(num[0:6])
extent = float(num[6:10])
extent = extent / 100
return worth, extent
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/longfeiw07/FundCalculator.git
[email protected]:longfeiw07/FundCalculator.git
longfeiw07
FundCalculator
FundCalculator
master

搜索帮助