Beispiel #1
0
 def parse_manager_detail(self, response):
     item = response.meta.get("item")
     manager_id, manager_name, company_id, company_name = item.get(
         "manager_id"), item.get("manager_name"), item.get(
             "company_id"), item.get("company_name")
     response = etree.HTML(response.text)
     fund_list = response.xpath("//div[@class='content_in']//tbody/tr")
     for fund in fund_list:
         item = dict()
         item["manager_id"] = manager_id
         item["manager_name"] = manager_name
         item["company_id"] = company_id
         item["company_name"] = company_name
         item["avatar"] = response.xpath("//img[@id='photo']/@src")[0]
         item["start_day"] = response.xpath(
             "//div[@class='right jd ']/text()")[3].strip()
         item["scale"] = response.xpath(
             "//div[@class='gmleft gmlefts ']//span[@class='redText']/text()"
         )[0]
         item["scale"] = eval(item["scale"])
         item["best_reward"] = response.xpath(
             "//div[@class='gmleft']//span[@class='numtext']/span/text()"
         )[0]
         item["description"] = response.xpath(
             "//div[@class='jlinfo clearfix']/div[@class='right ms']/p//text()"
         )[-1].strip()
         item["fund_id"] = "\t" + fund.xpath("./td[1]/a/text()")[0]
         item["fund_name"] = fund.xpath("./td[2]/a/text()")[0]
         save_item_in_csv(item, "manager_{}.csv".format(str_now_day),
                          self.title_num)
         self.title_num = 1
         print(item)
Beispiel #2
0
 def parse_fund_earning_perday(self, response):
     item = response.meta.get("item")
     code = item.get("code")
     fund_type = item.get("fund_type")
     name = item.get("name")
     response = response.text
     data = re.findall(r'\((.*?)\)$', response)[0]
     data = json.loads(data)
     for i in data.get("Data").get("LSJZList"):
         item = {
             "fund_type": fund_type,
             "code": code,
             "name": name,
             "date": i.get("FSRQ"),
             "total_day": data.get("TotalCount"),
             "net_value": i.get("DWJZ"),
             "accumulative_value": i.get("LJJZ"),
             "rate_day": i.get("JZZZL"),
             "buy_status": i.get("SGZT"),
             "sell_status": i.get("SHZT"),
             "profit": i.get("FHSP")
         }
         print(item), save_item_in_csv(
             item, "fund_earning_perday_{}.csv".format(str_now_day),
             self.title_num_2_1)
         self.title_num_2_1 = 1
Beispiel #3
0
 def parse_fund_basic_info(self, response):
     item = response.meta.get("item")
     code = item.get("code")
     response = etree.HTML(response.text)
     item = {"full_name": response.xpath("//th[text()='基金全称']/../td[1]/text()"), "code": code,
             "fund_url": 'http://fundf10.eastmoney.com/jbgk_{}.html'.format(code.strip()),
             "type": response.xpath("//th[text()='基金类型']/../td[2]/text()"),
             "publish_date": response.xpath("//th[text()='发行日期']/../td[1]/text()"),
             "setup_date_and_scale": response.xpath("//th[text()='成立日期/规模']/../td[2]/text()"),
             "asset_scale": response.xpath("//th[text()='资产规模']/../td[1]/text()"),
             "amount_scale": response.xpath("//th[text()='份额规模']/../td[2]/a/text()"),
             "company": response.xpath("//th[text()='基金管理人']/../td[1]/a/text()"),
             "company_url": response.xpath("//th[text()='基金管理人']/../td[1]/a/@href"),
             "bank": response.xpath("//th[text()='基金托管人']/../td[2]/a/text()"),
             "bank_url": response.xpath("//th[text()='基金托管人']/../td[2]/a/@href"),
             "manager": response.xpath("//th[text()='基金经理人']/../td[1]//a/text()"),
             "manager_url": response.xpath("//th[text()='基金经理人']/../td[1]//a/@href"),
             "profit_situation": response.xpath("//th[text()='基金经理人']/../td[2]/a/text()"),
             "management_feerate": response.xpath("//th[text()='管理费率']/../td[1]/text()"),
             "trustee_feerate": response.xpath("//th[text()='托管费率']/../td[2]/text()"),
             "standard_compared": response.xpath("//th[text()='业绩比较基准']/../td[1]/text()"),
             "followed_target": response.xpath("//th[text()='跟踪标的']/../td[2]/text()")}
     for i_name in ["full_name", "type", "publish_date", "setup_date_and_scale", "asset_scale", "amount_scale",
                    "company", "company_url", "bank", "bank_url", "manager", "manager_url", "profit_situation",
                    "management_feerate", "trustee_feerate", "standard_compared", "followed_target"]:
         item[i_name] = item[i_name][0] if len(item[i_name]) > 0 else None
     for i in ["company_url", "bank_url", "manager_url"]:
         item[i] = "http:" + item[i]
     print(item), save_item_in_csv(item, "fund_basic_info_{}.csv".format(str_now_day), self.title_num_2_2)
     self.title_num_2_2 = 1
Beispiel #4
0
 def parse_company_fundscale(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     item = {
         "company_code": company_code,
         "company_shortName": company_shortName,
         "fund_type": response.xpath("//tr[1]/th[2]/span/text()"),
         "fund_scale": response.xpath("//tr[2]/td[2]/text()"),
         "fund_scale_mean": response.xpath("//tr[2]/td[3]/text()"),
         "fund_scale_rank": response.xpath("//tr[2]/td[4]/text()"),
         "fund_amount": response.xpath("//tr[3]/td[2]/text()"),
         "fund_amount_mean": response.xpath("//tr[3]/td[3]/text()"),
         "fund_amount_rank": response.xpath("//tr[3]/td[4]/text()"),
         "fund_manager_amount": response.xpath("//tr[4]/td[2]/text()"),
         "fund_manager_amount_mean": response.xpath("//tr[4]/td[3]/text()"),
         "fund_manager_amount_rank": response.xpath("//tr[4]/td[4]/text()")
     }
     for i_name in [
             'fund_type', 'fund_scale', 'fund_scale_mean',
             'fund_scale_rank', 'fund_amount', 'fund_amount_mean',
             'fund_amount_rank', 'fund_manager_amount',
             'fund_manager_amount_mean', 'fund_manager_amount_rank'
     ]:
         item[i_name] = item[i_name][0] if len(item[i_name]) > 0 else None
     print(item), save_item_in_csv(
         item, "company_fundscale_{}.csv".format(str_now_day),
         self.title_num_2_2)
     self.title_num_2_2 = 1
Beispiel #5
0
 def parse_fund_position(self, response):
     item = response.meta.get("item")
     code = item.get("code")
     fund_type = item.get("fund_type")
     name = item.get("name")
     response = response.body.decode()
     response = re.findall(r'var apidata={ content:(.*?),arryear', response)[0]
     response = etree.HTML(response)
     div_list = response.xpath("//div[@class='boxitem w790']")
     for div in div_list:
         label = div.xpath(".//label[@class='left']/text()")[0].strip()
         time_1 = div.xpath(".//label[@class='right lab2 xq505']/font/text()")[0].strip()
         tr_list = div.xpath(".//table[@class='w782 comm tzxq']/tbody/tr")
         for tr in tr_list:
             # 单位万股,万元
             item = {"code": code, "name": name, "fund_type": fund_type, "label": label, "time": time_1,
                     "stock_code": "\t" + tr.xpath("./td[2]/a/text()")[0],  # 为了把0开头的存入,加tab
                     "stock_name": tr.xpath("./td[3]/a/text()"),
                     "stock_proportion": tr.xpath("./td[last()-2]/text()"),  # 持仓占净值比例
                     "stock_amount": tr.xpath("./td[last()-1]/text()"),  # 持仓股数,万股
                     "stock_value": tr.xpath("./td[last()]/text()")}  # 持仓市值,万元
             for i_name in ["stock_name", "stock_proportion", "stock_amount", "stock_value"]:
                 item[i_name] = item[i_name][0] if len(item[i_name]) > 0 else None
             print(item), save_item_in_csv(item, "fund_stock10_{}.csv".format(str_now_day), self.title_num_2_3)
             self.title_num_2_3 = 1
Beispiel #6
0
 def parse(self, response):
     response = response.text
     response = re.findall(r'=(.*?)$', response)[0]
     response = json.loads(response)
     for i in response.get("data"):
         item = dict()
         item["marketType"] = i.get("MarketType")
         item["datetime"] = i.get("DetailDate")
         item["datetime"] = item["datetime"].replace('T00:00:00', '')
         item["total_net_in"] = round(i.get("DRCJJME") / 100, 2)  # 当日成交净买额
         item["total_in"] = round(i.get("MRCJE") / 100, 2)  # 买入成交额
         item["total_out"] = round(i.get("MCCJE") / 100, 2)  # 卖出成交额
         item["today_in"] = round(i.get("DRZJLR") / 100,
                                  2)  # 当日资金流入 同花顺是这个!包含了当日成交净买额 + 申报未成交的部分
         item["grand_total_in"] = round(i.get("LSZJLR") / 100,
                                        2)  # 历史资金累计流入 当日资金流入的合计
         item["today_balance"] = round(i.get("DRYE") / 100, 2)  # 当日余额
         item["stock_code"] = "\t" + i.get("LCGCode")
         item["stock"] = i.get("LCG")
         item["stock_up"] = round(i.get("LCGZDF"), 2)
         item["sz_index"] = i.get("SSEChange")
         item["sz_index_percent"] = round(
             i.get("SSEChangePrecent") * 100, 2)
         print(item), save_item_in_csv(
             item, "beixiang_{}.csv".format(str_now_day), self.title_num)
         self.title_num = 1
Beispiel #7
0
    def parse(self, response):
        response = response.text
        # data1 沪股通十大成交股
        data1 = re.findall(r'var DATA1 = (.*?);', response)[0]
        data1 = json.loads(data1)
        for i in data1.get("data"):
            item = dict()
            item["marketType"] = str(int(i.get("MarketType")))
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(i.get("Rank")))
            item["code"] = i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            item["net_in"] = round(i.get("HGTJME") / 100000000, 2)
            item["in"] = round(i.get("HGTMRJE") / 100000000, 2)
            item["out"] = round(i.get("HGTMCJE") / 100000000, 2)
            item["total"] = round(i.get("HGTCJJE") / 100000000, 2)
            print(item), save_item_in_csv(
                item, "beixiang_10stock_{}.csv".format(str_now_day),
                self.title_num_1)
            self.title_num_1 = 1

        # data2 深股通十大成交股
        data2 = re.findall(r'var DATA2 = (.*?);', response)[0]
        data2 = json.loads(data2)
        for i in data2.get("data"):
            item = dict()
            item["marketType"] = str(int(i.get("MarketType")))
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(i.get("Rank")))
            item["code"] = i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            item["net_in"] = round(i.get("SGTJME") / 100000000, 2)
            item["in"] = round(i.get("SGTMRJE") / 100000000, 2)
            item["out"] = round(i.get("SGTMCJE") / 100000000, 2)
            item["total"] = round(i.get("SGTCJJE") / 100000000, 2)
            print(item), save_item_in_csv(
                item, "beixiang_10stock_{}.csv".format(str_now_day),
                self.title_num_1)
            self.title_num_1 = 1
Beispiel #8
0
 def parse_company_info(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     item = {
         "company_code":
         company_code,
         "company_shortName":
         company_shortName,
         "company_name":
         response.xpath("//p[@class='ttjj-panel-main-title']/text()"),
         "position":
         response.xpath(
             "//div[@class='firm-contact clearfix']/div[1]/p[1]/label/text()"
         ),
         "general_manager":
         response.xpath(
             "//div[@class='firm-contact clearfix']/div[1]/p[2]/label/text()"
         ),
         "website_url":
         response.xpath(
             "//div[@class='firm-contact clearfix']/div[2]/p[1]/label/text()"
         ),
         "tell":
         response.xpath(
             "//div[@class='firm-contact clearfix']/div[2]/p[2]/label/text()"
         ),
         "manager_total_asset":
         response.xpath("//a[text()='管理规模']/../label/text()"),
         "fund_amount":
         response.xpath(
             "//div[@class='fund-info']/ul/li[2]/label/a/text()"),
         "manager_amount":
         response.xpath(
             "//div[@class='fund-info']/ul/li[3]/label/a/text()"),
         "publish_date":
         response.xpath("//div[@class='fund-info']/ul/li[5]/label/text()"),
         "company_property":
         response.xpath("//div[@class='fund-info']/ul/li[6]/label/text()")
         [0].strip()
     }
     for i_name in [
             'company_name', 'position', 'general_manager', 'website_url',
             'tell', 'manager_total_asset', 'fund_amount', 'manager_amount',
             'publish_date'
     ]:
         item[i_name] = item[i_name][0] if len(item[i_name]) > 0 else None
     print(item), save_item_in_csv(
         item, "company_info_{}.csv".format(str_now_day),
         self.title_num_2_1)
     self.title_num_2_1 = 1
Beispiel #9
0
 def parse_company_industry_category(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     tr_list = response.xpath("//div[@id='contentWrap']/div[2]//tbody[1]/tr")[1:]  # 第一个是标题,不要
     for tr in tr_list:
         item = {"company_code": company_code,
                 "company_shortName": company_shortName,
                 "industry_category": tr.xpath("./td[2]/text()")[0],
                 "havein_mycomanpy_fund": tr.xpath("./td[4]/a/text()")[0],
                 "hold_in_value": tr.xpath("./td[5]/text()")[0], "stock_value": tr.xpath("./td[6]/text()")[0]}
         print(item), save_item_in_csv(item, "company_industry_category_{}.csv".format(str_now_day),
                                       self.title_num_2_5)
         self.title_num_2_5 = 1
Beispiel #10
0
 def parse_company_fundList(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     tr_list = response.xpath("//tbody/tr")
     for tr in tr_list:
         item = {"company_code": company_code,
                 "company_shortName": company_shortName,
                 "fund_name": tr.xpath("./td/a[1]/text()"),
                 "fund_code": tr.xpath("./td/a[2]/text()")}
         item["fund_name"] = item["fund_name"][0] if len(item["fund_name"]) > 0 else None
         item["fund_code"] = "\t" + tr.xpath("./td/a[2]/text()")[0] if len(item["fund_code"]) > 0 else None
         print(item), save_item_in_csv(item, "company_fund_list_{}.csv".format(str_now_day), self.title_num_2_3)
         self.title_num_2_3 = 1
Beispiel #11
0
    def parse(self, response):
        fund_type = re.findall(r'kf&ft=(.*?)&rs=&gs=0&sc=zzf&st=desc', response.url)[0]
        response = response.text
        response = re.findall(r"var rankData = (.*?);$", response)[0]
        response = re.findall(r"\[(.*?)]", response)[0]
        fund_list = response.split('"')
        fund_list = [i for i in fund_list if i != ""]
        fund_list = [i for i in fund_list if i != ","]
        for fund in fund_list:
            f = fund.split(",")
            # 为了把0开头的存入,加tab
            item = {"fund_type": fund_type, "code": "\t" + f[0], "name": f[1], "today": f[3], "net_value": f[4],
                    "accumulative_value": f[5], "rate_day": f[6], "rate_recent_week": f[7], "rate_recent_month": f[8],
                    "rate_recent_3month": f[9], "rate_recent_6month": f[10], "rate_recent_year": f[11],
                    "rate_recent_2year": f[12], "rate_recent_3year": f[13], "rate_from_this_year": f[14],
                    "rate_from_begin": f[15], "rate_buy": f[20]}
            item["url"] = "http://fund.eastmoney.com/" + item["code"] + ".html"
            print(item), save_item_in_csv(item, "fund_earning_list_{}.csv".format(str_now_day), self.title_num_1)
            self.title_num_1 = 1

            # 2.1基金成立以来每日净值
            if self.need_fund_earning_perday:
                yield scrapy.Request(
                    "http://api.fund.eastmoney.com/f10/lsjz?callback=jQuery183036648984792081185_1575425405289&"
                    "fundCode={}"
                    "&pageIndex=1&pageSize=20".format(item.get("code").strip()),  # pageSize写2万一次加载完。一个月就写20。
                    headers={"Referer": "http://fundf10.eastmoney.com"},
                    callback=self.parse_fund_earning_perday,
                    meta={"item": item},
                )
            # 2.2基金基本信息
            if self.need_fund_basic_info:
                yield scrapy.Request(
                    "http://fundf10.eastmoney.com/jbgk_{}.html".format(item["code"].strip()),
                    callback=self.parse_fund_basic_info,
                    meta={"item": item},
                )
            # 2.3基金10大持仓股(指定按年)
            if self.need_fund_position:
                for year in ["2020", "2021"]:
                    yield scrapy.Request(
                        "http://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=jjcc&code={}&topline=10&year={}"
                        "&month=".format(item["code"].strip(), year),
                        callback=self.parse_fund_position,
                        meta={"item": item},
                    )
Beispiel #12
0
 def parse_company_10stock(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     tr_list = response.xpath("//div[@id='contentWrap']/div[2]//tbody[1]/tr")
     for tr in tr_list:
         item = dict()
         item["company_code"] = company_code
         item["company_shortName"] = company_shortName
         item["stock_code"] = tr.xpath("./td[2]/a/text()")[0]
         item["stock_code"] = "\t" + item["stock_code"]
         item["stock_name"] = tr.xpath("./td[3]/a/text()")[0]
         item["havein_mycomanpy_fund"] = tr.xpath("./td[5]/a/text()")[0]  # 本公司持有基金数
         item["hold_in_value"] = tr.xpath("./td[6]/text()")[0]  # 占总净值比例
         item["stock_amount"] = tr.xpath("./td[7]/text()")[0]  # 持股数(万股)
         item["stock_value"] = tr.xpath("./td[8]/text()")[0]  # 持仓市值(万元)
         print(item), save_item_in_csv(item, "company_10stock_{}.csv".format(str_now_day), self.title_num_2_4)
         self.title_num_2_4 = 1
Beispiel #13
0
 def parse(self, response):
     response = re.findall(r'\((.*?)\);$', response.text)[0]
     response = json.loads(response)
     for i in response.get("data").get("klines"):
         item = {
             "code": response.get("data").get("code"),
             "name": response.get("data").get("name"),
             "datetime": i.split(",")[0],
             "price_start": i.split(",")[1],
             "price_end": i.split(",")[4],
             "price_max": i.split(",")[3],
             "amount": i.split(",")[5],
             "value": i.split(",")[6],
             "swing": i.split(",")[7]
         }
         print(item), save_item_in_csv(
             item, "market_index_{}.csv".format(str_now_day),
             self.title_num_1)
         self.title_num_1 = 1
Beispiel #14
0
 def parse_company_industry_category(self, response):
     item = response.meta.get("item")
     company_code = item.get("company_code")
     company_shortName = item.get("company_shortName")
     response = etree.HTML(response.body.decode())
     tr_list = response.xpath(
         "//table[@class='ttjj-table ttjj-table-hover']//tr")[1:]  # [1:]去标题
     for tr in tr_list:
         item = {
             "company_code": company_code,
             "company_shortName": company_shortName,
             "industry_category": tr.xpath("./td[2]/text()")[0],
             "havein_mycomanpy_fund": tr.xpath("./td[4]/a/text()")[0],
             "hold_in_value_percent": tr.xpath("./td[5]/text()")[0],
             "stock_value": tr.xpath("./td[6]/text()")[0]
         }
         print(item), save_item_in_csv(
             item, "company_industry_category_{}.csv".format(str_now_day),
             self.title_num_2_5)
         self.title_num_2_5 = 1
Beispiel #15
0
    def parse(self, response):
        response = response.text
        # data1 沪股通十大成交股
        data1 = re.findall(r'var DATA1 = (.*?);', response)[0]
        data1 = json.loads(data1)
        for i in data1.get("data"):
            item = dict()
            item["marketType"] = str(int(i.get("MarketType")))
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(i.get("Rank")))
            item["code"] = "\t" + i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            item["net_in"] = round(i.get("HGTJME") / 10**8, 2)
            item["in"] = round(i.get("HGTMRJE") / 10**8, 2)
            item["out"] = round(i.get("HGTMCJE") / 10**8, 2)
            item["total"] = round(i.get("HGTCJJE") / 10**8, 2)
            print(item), save_item_in_csv(
                item, "beixiang_20stock_{}.csv".format(str_now_day),
                self.title_num_1)
            self.title_num_1 = 1

        # data2 深股通十大成交股
        data2 = re.findall(r'var DATA2 = (.*?);', response)[0]
        data2 = json.loads(data2)
        for i in data2.get("data"):
            item = dict()
            item["marketType"] = str(int(i.get("MarketType")))
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(i.get("Rank")))
            item["code"] = "\t" + i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            item["net_in"] = round(i.get("SGTJME") / 10**8, 2)
            item["in"] = round(i.get("SGTMRJE") / 10**8, 2)
            item["out"] = round(i.get("SGTMCJE") / 10**8, 2)
            item["total"] = round(i.get("SGTCJJE") / 10**8, 2)
            print(item), save_item_in_csv(
                item, "beixiang_20stock_{}.csv".format(str_now_day),
                self.title_num_1)
            self.title_num_1 = 1

        # data3 港股通(沪)十大成交股
        data3 = re.findall(r'var DATA3 = (.*?);', response)[0]
        data3 = json.loads(data3)

        # 若data3里面已经有了data4的数据,则跳过
        item_dict = set()
        for i in data3.get("data"):
            item = dict()
            # 基本信息
            item["marketType"] = i.get("MarketType")
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(i.get("Rank")))
            item["code"] = "\t" + i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            # 港股通(沪)
            item["net_in_h"] = round(i.get("GGTHJME") / 10**8,
                                     2) if i.get("GGTHJME") != "-" else 0
            item["in_h"] = round(i.get("GGTHMRJE") /
                                 10**8, 2) if i.get("GGTHMRJE") != "-" else 0
            item["out_h"] = round(i.get("GGTHMCJE") /
                                  10**8, 2) if i.get("GGTHMCJE") != "-" else 0
            item["total_h"] = round(i.get("GGTHCJJE") / 10**8,
                                    2) if i.get("GGTHCJJE") != "-" else 0
            # 港股通(深)
            item["net_in_s"] = round(i.get("GGTSJME") / 10**8,
                                     2) if i.get("GGTSJME") != "-" else 0
            item["in_s"] = round(i.get("GGTSMRJE") /
                                 10**8, 2) if i.get("GGTSMRJE") != "-" else 0
            item["out_s"] = round(i.get("GGTSMCJE") /
                                  10**8, 2) if i.get("GGTSMCJE") != "-" else 0
            item["total_s"] = round(i.get("GGTSCJJE") / 10**8,
                                    2) if i.get("GGTSCJJE") != "-" else 0
            # 港股通合计(沪+深)
            item["net_in"] = round(i.get("GGTJME") /
                                   10**8, 2) if i.get("GGTJME") != "-" else 0
            item["total"] = round(i.get("GGTCJL") /
                                  10**8, 2) if i.get("GGTCJL") != "-" else 0
            print("data3", item), save_item_in_csv(
                item, "nanxiang_20stock_{}.csv".format(str_now_day),
                self.title_num_2)
            self.title_num_2 = 1
            item_dict.add(item.get("code"))

        # data4 港股通(深)十大成交股
        data4 = re.findall(r'var DATA4 = (.*?);', response)[0]
        data4 = json.loads(data4)
        for i in data4.get("data"):
            item = dict()
            # 若data3里面已经有了data4的数据,则跳过
            if "\t" + i.get("Code") in item_dict:
                continue
            # 基本信息
            item["marketType"] = i.get("MarketType")
            item["date_time"] = i.get("DetailDate")
            item["date_time"] = item["date_time"].replace('T00:00:00', '')
            item["rank"] = str(int(
                i.get("Rank"))) if i.get("Rank") != "-" else 0
            item["code"] = "\t" + i.get("Code")
            item["name"] = i.get("Name")
            item["close"] = i.get("Close")
            item["changePercent"] = i.get("ChangePercent")
            # 单位亿,净买入,买入,卖出,成交额(买+卖)
            # 港股通(沪)
            item["net_in_h"] = round(i.get("GGTHJME") / 10**8,
                                     2) if i.get("GGTHJME") != "-" else 0
            item["in_h"] = round(i.get("GGTHMRJE") /
                                 10**8, 2) if i.get("GGTHMRJE") != "-" else 0
            item["out_h"] = round(i.get("GGTHMCJE") /
                                  10**8, 2) if i.get("GGTHMCJE") != "-" else 0
            item["total_h"] = round(i.get("GGTHCJJE") / 10**8,
                                    2) if i.get("GGTHCJJE") != "-" else 0
            # 港股通(深)
            item["net_in_s"] = round(i.get("GGTSJME") / 10**8,
                                     2) if i.get("GGTSJME") != "-" else 0
            item["in_s"] = round(i.get("GGTSMRJE") /
                                 10**8, 2) if i.get("GGTSMRJE") != "-" else 0
            item["out_s"] = round(i.get("GGTSMCJE") /
                                  10**8, 2) if i.get("GGTSMCJE") != "-" else 0
            item["total_s"] = round(i.get("GGTSCJJE") / 10**8,
                                    2) if i.get("GGTSCJJE") != "-" else 0
            # 港股通合计(沪+深)
            item["net_in"] = round(i.get("GGTJME") /
                                   10**8, 2) if i.get("GGTJME") != "-" else 0
            item["total"] = round(i.get("GGTCJL") /
                                  10**8, 2) if i.get("GGTCJL") != "-" else 0
            print("data4", item), save_item_in_csv(
                item, "nanxiang_20stock_{}.csv".format(str_now_day),
                self.title_num_2)
            self.title_num_2 = 1
Beispiel #16
0
    def parse(self, response):
        response_url = response.url

        # 沪股通十大成交股
        if "MarketType=1" in response_url:
            response = eval(response.text)
            for i in response:
                item = dict()
                item = get_item(i, item)
                item["rank"] = str(int(i.get("Rank")))
                # 单位亿,净买入,买入,卖出,成交额(买+卖)
                item["net_in"] = round(i.get("HGTJME") / 10 ** 8, 2)
                item["in"] = round(i.get("HGTMRJE") / 10 ** 8, 2)
                item["out"] = round(i.get("HGTMCJE") / 10 ** 8, 2)
                item["total"] = round(i.get("HGTCJJE") / 10 ** 8, 2)
                print("沪股通十大成交股:", item)
                save_item_in_csv(item, "beixiang_10stock_{}.csv".format(str_now_day), self.title_num_1)
                self.title_num_1 = 1

        # 深股通十大成交股
        elif "MarketType=3" in response_url:
            response = eval(response.text)
            for i in response:
                item = dict()
                item = get_item(i, item)
                item["rank"] = str(int(i.get("Rank")))
                # 单位亿,净买入,买入,卖出,成交额(买+卖)
                item["net_in"] = round(i.get("SGTJME") / 10 ** 8, 2)
                item["in"] = round(i.get("SGTMRJE") / 10 ** 8, 2)
                item["out"] = round(i.get("SGTMCJE") / 10 ** 8, 2)
                item["total"] = round(i.get("SGTCJJE") / 10 ** 8, 2)
                print("深股通十大成交股:", item)
                save_item_in_csv(item, "beixiang_10stock_{}.csv".format(str_now_day), self.title_num_1)
                self.title_num_1 = 1

        # 港股通(沪)十大成交股
        elif "MarketType=2" in response_url:
            response = eval(response.text)
            for i in response:
                item = dict()
                item = get_item(i, item)
                item["rank"] = str(int(i.get("Rank")))
                # 单位亿,净买入,买入,卖出,成交额(买+卖)
                item["net_in"] = round(i.get("GGTHJME") / 10 ** 8, 2)
                item["in"] = round(i.get("GGTHMRJE") / 10 ** 8, 2)
                item["out"] = round(i.get("GGTHMCJE") / 10 ** 8, 2)
                item["total"] = round(i.get("GGTHCJJE") / 10 ** 8, 2)
                print("港股通(沪)十大成交股:", item)
                save_item_in_csv(item, "nanxiang_10stock_{}.csv".format(str_now_day), self.title_num_2)
                self.title_num_2 = 1

        # 港股通(深)十大成交股
        elif "MarketType=4" in response_url:
            response = eval(response.text)
            for i in response:
                item = dict()
                item = get_item(i, item)
                item["rank"] = str(int(i.get("Rank1")))
                # 单位亿,净买入,买入,卖出,成交额(买+卖)
                item["net_in"] = round(i.get("GGTSJME") / 10 ** 8, 2)
                item["in"] = round(i.get("GGTSMRJE") / 10 ** 8, 2)
                item["out"] = round(i.get("GGTSMCJE") / 10 ** 8, 2)
                item["total"] = round(i.get("GGTSCJJE") / 10 ** 8, 2)
                print("港股通(深)十大成交股:", item)
                save_item_in_csv(item, "nanxiang_10stock_{}.csv".format(str_now_day), self.title_num_2)
                self.title_num_2 = 1