import requests  # 导入requests包
from bs4 import BeautifulSoup
from urllib import request
import re
import pymongo
import timemongo_client = pymongo.MongoClient('mongodb://localhost:27017/')
# 若没有Database 和Collection,则会自动创建
mongo_db = mongo_client['quant_01']
mongo_collection = mongo_db['EPS_Stock']
mongo_stock_code = mongo_db['basic']
all_stock_code = []
Furl = 'http://stockpage.10jqka.com.cn/'
mydoc = mongo_stock_code.find()
for x in mydoc:# print(x['symbol'])all_stock_code.append(x['symbol'])'''
Company name:', 'Net assets per share:', 'Earnings per share:', 'Net profit:', 'Net profit growth rate:',
'Net profit growth rate:', 'Operating income:', ' Total share capital: ', 'tradable shares:
'''headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3877.400 QQBrowser/10.8.4507.400'
}
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = {'username': 'cqc', 'password': 'XXXX'}
headers2 = {'User-Agent': user_agent}all_list = []
for i in range(35929, len(all_stock_code)):start = time.time()try:# 同花顺下载数据Furl = 'http://stockpage.10jqka.com.cn/'url = Furl + all_stock_code[i]print(url)req = request.Request(url=url, headers=headers)rsp = request.urlopen(req, timeout=30)# print(rsp.read().decode('utf-8'))html = rsp.read().decode('utf-8')bf = BeautifulSoup(html, "html.parser")texts = bf.find_all('dl', class_='company_details')str_Result = str(texts)# print(str_Result)splitR = str_Result.splitlines()print(splitR)print(len(splitR))# "<dd.+?/dd>|<dt.+?/dt>"   "<dd.+?/dd>|<dt.+?/dt>"gm# print('+++++++++++++++++++++++++++++++++++++++++++')result = re.findall(r"<dd.+?/dd>|<dt.+?/dt>", str_Result, flags=0)# print(result)# print(len(result))num_list1 = []num_list2 = []for i in range(len(result)):if result[i].find('公司名称:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('上市时间:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('每股净资产:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('每股收益:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('净利润:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:pass# if result[i].find('净利润增长率') > -1:#     num_list1.append(result[i])#     num_list2.append(result[i + 1])# else:#     pass   # find 无法区分包含及等于 会查找出净利润==净利润增长率if result[i].find('营业收入:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('总股本:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passif result[i].find('流通股:') > -1:num_list1.append(result[i])num_list2.append(result[i + 1])else:passprint('$$$$$$$$$$$$$$$$$$$$$$$$$')Important_Books1 = ['Company_Name', 'Net_assets_per_share', 'EPS', 'Net_Profit','operating income', 'total_share_capital', 'floating stock']Important_Books2 = []for m in num_list2:Important_Books2.append(m[4:-5])print(Important_Books2)dict1 = dict(zip(Important_Books1, Important_Books2))# print(dict1)all_list.append(dict1)except:result_time = time.time() - startprint("program over time:" + str(result_time))break'''        列表转字典
list1 = ['key1','key2','key3']
list2 = ['1','2','3']
dict(zip(list1,list2))
{'key1':'1','key2':'2','key3':'3'}
'''
print('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&')
print(all_list)
mongo_collection.insert_many(all_list)# 公司名称:company name
# 每股净资产:Net asset value per share
# 每股收益:EPS
# 净利润:net profit
# 营业收入:operating income
# 总股本:total shares
# 流通股:floating stock
import re
import pymongo
import timemongo_client = pymongo.MongoClient('mongodb://localhost:27017/')
# 若没有Database 和Collection,则会自动创建
mongo_db = mongo_client['quant_01']
mongo_collection = mongo_db['EPS_Stock']
mongo_stock_code = mongo_db['basic']mydoc = mongo_stock_code.find()
i=0
for x in mydoc:print(str(i)+'    '+x['symbol']+x['name'])i=i+1# 中色股份

[049量化交易]python同花顺下载数据写入MongoDB数据库相关推荐

  1. [020量化交易] python读取股票信息并写入数据库2

    import json import tushare as ts import time import sqlite3 import pandas as pd# 初始化pro接口 pro = ts.p ...

  2. python同花顺自动交易软件下载_GitHub - touzi-platform/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  3. python 同花顺thstrader_GitHub - yanjlee/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  4. python 同花顺thstrader_GitHub - fswzb/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  5. 同花顺python_GitHub - nladuo/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 暂时无法更新 因为个人时间问题,这个项目搁置已久,断断续续更新过几次,10月份应该时间会闲下来很多 ...

  6. python 同花顺thstrader_GitHub - python8642/THSTrader-2: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  7. python 同花顺thstrader_GitHub - skyformat99/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  8. python 同花顺thstrader_GitHub - sz982005/THSTrader-1: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

  9. python 同花顺thstrader_GitHub - python8642/THSTrader: 量化交易。同花顺免费模拟炒股软件客户端的python API。(Python3)...

    THSTrader 量化交易.同花顺免费模拟炒股软件客户端的python API.(Python3) 为什么有这个项目 本来看到了这个easytrader这个项目,不过这个客户端已经过时了(被强制更新 ...

最新文章

  1. 再见,PyTorch!
  2. 微信小程序(11)--购物车
  3. 使用CDN之后APACHE日志记录中IP地址不正确的解决方案
  4. 用Python 给你的个人微信朋友圈数据生成一本电子书吧!
  5. eclipse java jdk_设置Eclipse和Java JDK
  6. hdu 5587(数学规律)
  7. 实现ftoa与itoa
  8. 计算机考试题操作题答案,全国计算机等级考试模拟题一(带操作题及答案)
  9. routersploit简单实例
  10. “锤死挣扎”的骁龙845+128GB旗舰机暴降1500元 仍冷清!
  11. ajax取消数据获取
  12. knn约会_出色的在线约会预订系统应具备的5个功能
  13. c# 实现查找mysql安装路径
  14. nginx 做代理转发 对文件上传下载有影响速度吗_少年: Nginx了解下
  15. 基于Matlab的数字图像gui界面设计
  16. java随机生成迷宫游戏地图_java随机生成迷宫(图的深度优先遍历)
  17. HTML常用语法及标签(第一天所学)
  18. Docker配置mc服务器
  19. k8s节点资源耗尽处理
  20. WSL嵌入式开发系列教程 4 —— 安装VS code

热门文章

  1. 2021 MySQL安装和卸载 以及 视图软件安装(图文教程)超详细
  2. 数据中台建设(七):数据资产管理
  3. sublime c语言插件,sublime text c语言开发环境插件集合
  4. 今日头条APK瘦身之路
  5. Daz Studio打开时提示Resource Error的解决方法
  6. diff和patch 打补丁
  7. MATLAB实现周期信号的傅里叶级数的展开
  8. java计算机毕业设计临时停车收费系统源码+系统+数据库+lw文档+mybatis+运行部署
  9. Google PLB(Protective Load Balancing) 简评
  10. C语言程序绘制菱形,C语言画出菱形