From bd9b254cb937518a59834e7a431e410bf0a2946d Mon Sep 17 00:00:00 2001 From: 1nchaos Date: Fri, 9 Aug 2024 22:34:01 +0800 Subject: [PATCH] fixed concept code ths --- adata/stock/info/concept/stock_concept_ths.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/adata/stock/info/concept/stock_concept_ths.py b/adata/stock/info/concept/stock_concept_ths.py index 1ea6539..0350d8e 100644 --- a/adata/stock/info/concept/stock_concept_ths.py +++ b/adata/stock/info/concept/stock_concept_ths.py @@ -157,6 +157,9 @@ def __index_constituent_ths_by_concept_code(self, concept_code=None, wait_time=N page_info = soup.find('span', {'class': 'page_info'}) if page_info: total_pages = int(page_info.text.split("/")[1]) + # 只能获取到前5页 + if total_pages > 5: + total_pages = 5 # 4. 解析数据 page_data = [] for idx, tr in enumerate(soup.find_all('tr')): @@ -226,12 +229,14 @@ def __index_constituent_ths_by_name(self, name=None, wait_time=None): total_pages = 1 curr_page = 1 while curr_page <= total_pages: - api_url = f"https://www.iwencai.com/gateway/urp/v7/landing/getDataList?query={name} 概念成分&" \ - f"page={curr_page}&perpage=100&query_type=stock&comp_id=6734520&uuid=24087" + api_url = f"http://www.iwencai.com/gateway/urp/v7/landing/getDataList?query={name} 概念成分股有哪些&" \ + f"urp_sort_way=desc&urp_sort_index=最新涨跌幅&page={curr_page}&perpage=100&addheaderindexes=&codelist=&" \ + f"indexnamelimit=&ret=json_all&date_range[0]=20240809&urp_use_sort=1&query_type=stock&" \ + f"comp_id=6836372&business_cat=soniu&uuid=24087" headers = copy.deepcopy(ths_headers.json_headers) headers['Host'] = 'www.iwencai.com' headers['Sec-Fetch-Mode'] = 'navigate' - res = requests.request(method='get', url=api_url, headers=headers, proxies={}, wait_time=wait_time) + res = requests.request(method='post', url=api_url, headers=headers, proxies={}, wait_time=wait_time) curr_page += 1 # 2. 判断请求是否成功 if res.status_code != 200: @@ -289,6 +294,7 @@ def get_concept_ths(self, stock_code: str = '000001'): if __name__ == '__main__': - # print(StockConceptThs().all_concept_code_ths()) - print(StockConceptThs().get_concept_ths(stock_code='300033')[ - ['stock_code', 'concept_code', 'name', 'source','reason']].to_string()) + print(StockConceptThs().all_concept_code_ths()) + print(StockConceptThs().concept_constituent_ths(name='生物医药')) + print(StockConceptThs().concept_constituent_ths(index_code='885403')) + print(StockConceptThs().concept_constituent_ths(concept_code='300769'))