1 Star 0 Fork 1

joozen/stock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
new_stock_fund.py 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
Rockyzsu 提交于 2019-10-24 00:33 . update
# -*- coding: utf-8 -*-
# website: http://30daydo.com
# @Time : 2019/10/24 0:03
# @File : new_stock_fund.py
# 获取打新基金数据
import requests
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import logging
from scrapy.selector import Selector
logger = logging.getLogger()
PATH = r'C:\OneDrive\Python\selenium\chromedriver.exe'
class TianTianFund():
def __init__(self):
# 未上市
self.wss_url='http://fund.eastmoney.com/data/dxgjj_xgccjjyl.html#wss;SUMPLACE;desc;1'
options = webdriver.ChromeOptions()
options.add_argument(
'--user-agent=Mozilla/5.0 (Windows NT 999999.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
self.driver = webdriver.Chrome(executable_path=PATH,
chrome_options=options)
def get_fund(self):
self.driver.get(self.wss_url)
time.sleep(5)
text=self.driver.page_source
response = Selector(text=text)
nodes = response.xpath('//tbody[@id="datalistwss_body"]/tr')
for node in nodes:
code = node.xpath('.//td[2]/a/text()').extract_first()
name = node.xpath('.//td[3]/a/text()').extract_first()
hit_count = node.xpath('.//td[6]/a[1]/text()').extract_first()
fund_url = node.xpath('.//td[6]/a[1]/@href').extract_first()
full_url = 'http://fund.eastmoney.com/data/'+fund_url
new_stock_amount = node.xpath('.//td[6]/text()').extract_first()
self.driver.get(fund_url)
time.sleep(5)
sub_response = Selector(text=self.driver.page_source)
sub_nodes = sub_response.xpath('//tbody[@id="datalist_body"]/tr')
new_stock_list = []
for sub_node in sub_nodes:
d={}
stock_code = sub_node.xpath('.//td[2]/a/text()').extract_first()
stock_name = sub_node.xpath('.//td[3]/a/text()').extract_first()
assign_mount = sub_node.xpath('.//td[9]/text()').extract_first()
d['新股代码']=stock_code
d['新股名称']=stock_name
d['中的金额-万元']=assign_mount
new_stock_list.append(d)
print(new_stock_list)
def start(self):
self.get_fund()
self.driver.close()
if __name__=='__main__':
fund = TianTianFund()
fund.start()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/joozen/stock.git
git@gitee.com:joozen/stock.git
joozen
stock
stock
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385