"""
中证智能财讯
"""
import json

import requests
from bs4 import BeautifulSoup


def zzcx():
    url = 'https://zzcx.cs.com.cn/dist/publishManuscript/listES'
    payload = {"pageNo": 1, "pageSize": 15, "statusList": [0], "keyword": ""}
    headers = {
        'Accept': 'application/json',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Content-Length': '56',
        'Content-Type': 'application/json;charset=UTF-8',
        'Cookie': 'zycna=VEwasVGF9akBAXuVA58n9CJm',
        'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
        'Sec-Ch-Ua-Mobile': '?0',
        'Sec-Ch-Ua-Platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        'Origin': 'https://zzcx.cs.com.cn',
        'Referer': 'https://zzcx.cs.com.cn/app/zzb/list?spm=0.0.0.0.wjnSUZ'
    }
    payload = json.dumps(payload)
    result_json = requests.post(url=url, data=payload, headers=headers).json()
    print(result_json)
    pages = result_json['data']['pages']
    for page in range(1, int(pages + 1)):
        payload_page = {"pageNo": page, "pageSize": 15, "statusList": [0], "keyword": ""}
        payload_page = json.dumps(payload_page)
        datas = requests.post(url=url, data=payload_page, headers=headers)
        records = datas.json()['data']['records']
        for news in records:
            title = news['title']
            news_url = 'https://zzcx.cs.com.cn/app/zzb/detail?id=' + news['manuscriptId']
            news_req = requests.get(url=news_url, headers=headers)
            news_soup = BeautifulSoup(news_req.content, 'html.parser')
            detail_info = news_soup.find('div', class_='subTitle___svblj')
            div_list = detail_info.find_all('div')
            origin = div_list[0].text
            publishDate = div_list[1].text


if __name__ == "__main__":
    zzcx()