
    fi.                     T   d Z ddlZddlZddlmZ dej        fdZddedej        fdZ	ddedej        fd
Z
ddedej        fdZedk    r\ e            Z ee            e	d          Z ee            e
d	          Z ee            ed	          Z ee           dS dS )u[   
Date: 2023/12/12 16:30
Desc: 基金评级
https://fund.eastmoney.com/data/fundrating.html
    N)BeautifulSoupreturnc                     d} t          j        |           }t          |j        d          }|                    dddi                              d          j        }d	 |                    d
          d                             d          d                                                             d                              d                              d                              d          D             }t          j	        |          }g d|_
        |g d         }t          j        |d         d          |d<   t          j        |d         d          |d<   t          j        |d         d          |d<   t          j        |d         d          |d<   t          j        |d         d          |d<   t          j        |d         j                            d          d          dz  |d<   |S )u   
    天天基金网-基金评级-基金评级总汇
    https://fund.eastmoney.com/data/fundrating.html
    :return: 基金评级总汇
    :rtype: pandas.DataFrame
    z/https://fund.eastmoney.com/data/fundrating.htmllxml)featuresdividfundinfo)nameattrsscriptc                 8    g | ]}|                     d           S |split.0items     C/usr/local/lib/python3.11/dist-packages/akshare/fund/fund_rating.py
<listcomp>z#fund_rating_all.<locals>.<listcomp>   2     	 	 	 	

3	 	 	    var   =   ;"r   |_)   代码   简称   类型   基金经理-   基金公司r%      5星评级家数r%   r%      招商证券r%      上海证券r%      晨星评级r%      济安金信r%   	   手续费r%   r%   r%   r%   r%   r%   r%   r%   )r!   r"   r$   r&   r'   r)   r(   r+   r*   r,   r#   r'   coerceerrorsr)   r(   r+   r*   r,   %d   )requestsgetr   textfindstringr   strippd	DataFramecolumns
to_numericstr)urlrsoup	data_textdata_contenttemp_dfs         r   fund_rating_allrC      s    <CSA&111D		uT:,>	??DDXNNUI	 	OOE**1-	sA		s	s	s	t	 	 	L l<((G  GO: 	
 	
 	
G #%-8J0KT\"]"]"]G mGN,CHUUUGN mGN,CHUUUGN mGN,CHUUUGN mGN,CHUUUGN
gk*.44S99(KKKcQ K Nr   20230630datec                 0   d}t          j        |          }t          |j        d          }d |                    dddi          D             }d                    | d	d
         | d
d         | dd	         g          }||vrddd                    | d	d
         | d
d         | dd	         g           d}t          j        |          }t          |j        d          }|                    dddi                              d          j        }d |                    d          d                             d          d                                                             d                              d                              d                              d          D             }t          j
        |          }g d|_        |g d         }t          j        |d         d          j        j        |d<   t          j        |d         d          |d<   t          j        |d          d          |d <   t          j        |d!         d          |d!<   t          j        |d"         d          |d"<   t          j        |d#         d          |d#<   t          j        |d$         d          |d$<   t          j        |d%         d          |d%<   t          j        |d&         d          |d&<   t          j        |d'         d          |d'<   |S )(u  
    天天基金网-基金评级-上海证券评级
    https://fund.eastmoney.com/data/fundrating_3.html
    :param date: 日期; https://fund.eastmoney.com/data/fundrating_3.html 获取查询日期
    :type date: str
    :return: 上海证券评级
    :rtype: pandas.DataFrame
    z1https://fund.eastmoney.com/data/fundrating_3.htmlr   c                     g | ]
}|d          S value r   s     r   r   z"fund_rating_sh.<locals>.<listcomp>g   )       W  r   selectr	   	rqoptionsr   r%   N   r   uN   请访问 https://fund.eastmoney.com/data/fundrating_3.html 获取查询日期z-https://fund.eastmoney.com/data/fundrating_3_.htmlr   r
   r   c                 8    g | ]}|                     d           S r   r   r   s     r   r   z"fund_rating_sh.<locals>.<listcomp>q   r   r   r   r   r   r   r   r   r    )r!   r"   r#   r$   _r&   rR      3年期评级-3年评级   3年期评级-较上期   5年期评级-5年评级   5年期评级-较上期   单位净值   日期   日增长率   近1年涨幅   近3年涨幅   近5年涨幅r,   rR   rR   rR   rR   )r!   r"   r$   r&   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r,   r#   rX   r-   r.   rS   rT   rU   rV   rW   rY   rZ   r[   r\   r2   r3   r   r4   r5   joinr6   r   r7   r8   r9   r:   to_datetimedtrE   r;   	rE   r=   r>   r?   	date_listdate_formatr@   rA   rB   s	            r   fund_rating_shrd   [   sG    >CSA((D "&))HT;<O)"P"P  I ((D!Hd1Q3iabb:;;K)##^^
j#((D!HdSTUVSViY]^_^`^`YaCb:c:c
j
j
jCSA((D		%j'9	::??IIPI	 	OOE**1-	sA		s	s	s	t	 	 	L l<((G  GO0 	
 	
 	
G( wx'8JJJMRGH*,-*+H+ + +G&' *,)*8* * *G%& +--*+H+ + +G&' *,)*8* * *G%& !mGN,CHUUUGN mGN,CHUUUGN!}W_-EhWWWGO!}W_-EhWWWGO!}W_-EhWWWGONr   20230331c                    d}t          j        |          }t          |j        d          }d |                    dddi          D             }d                    | d	d
         | d
d         | dd	         g          }||vrddd                    | d	d
         | d
d         | dd	         g           d}t          j        |          }t          |j        d          }|                    dddi                              d          j        }d |                    d          d                             d          d                                                             d                              d                              d                              d          D             }t          j
        |          }g d|_        |g d         }t          j        |d         d          j        j        |d<   t          j        |d         d          |d<   t          j        |d          d          |d <   t          j        |d!         d          |d!<   t          j        |d"         d          |d"<   t          j        |d#         d          |d#<   t          j        |d$         d          |d$<   t          j        |d%         d          |d%<   |S )&u(  
    天天基金网-基金评级-招商证券评级
    https://fund.eastmoney.com/data/fundrating_2.html
    :param date: 日期; https://fund.eastmoney.com/data/fundrating_2.html 获取查询日期
    :type date: str
    :return: 招商证券评级-混合型
    :rtype: pandas.DataFrame
    z1https://fund.eastmoney.com/data/fundrating_2.htmlr   c                     g | ]
}|d          S rH   rJ   r   s     r   r   z"fund_rating_zs.<locals>.<listcomp>   rK   r   rL   r	   rM   rN   r%   NrO   r   uN   请访问 https://fund.eastmoney.com/data/fundrating_2.html 获取查询日期z-https://fund.eastmoney.com/data/fundrating_2_rP   r   r
   r   c                 8    g | ]}|                     d           S r   r   r   s     r   r   z"fund_rating_zs.<locals>.<listcomp>   r   r   r   r   r   r   r   r   r    )r!   r"   rR   r$   rR   r&   rR   rS   rT   rW   rX   rY   rZ   r[   r\   r,   rR   rR   rR   rR   )r!   r"   r$   r&   rS   rT   rW   rX   rY   rZ   r[   r\   r,   rX   r-   r.   rS   rT   rW   rY   rZ   r[   r\   r]   ra   s	            r   fund_rating_zsri      s    >CSA((D "&))HT;<O)"P"P  I ((D!Hd1Q3iabb:;;K)##^^
j#((D!HdSTUVSViY]^_^`^`YaCb:c:c
j
j
jCSA((D		%j'9	::??IIPI	 	OOE**1-	sA		s	s	s	t	 	 	L l<((G  GO, 	
 	
 	
G" wx'8JJJMRGH*,-*+H+ + +G&' *,)*8* * *G%& !mGN,CHUUUGN mGN,CHUUUGN!}W_-EhWWWGO!}W_-EhWWWGO!}W_-EhWWWGONr   c                    d}t          j        |          }t          |j        d          }d |                    dddi          D             }d                    | d	d
         | d
d         | dd	         g          }||vrddd                    | d	d
         | d
d         | dd	         g           d}t          j        |          }t          |j        d          }|                    dddi                              d          j        }d |                    d          d                             d          d                                                             d                              d                              d                              d          D             }t          j
        |          }g d|_        |g d         }t          j        |d         d          j        j        |d<   t          j        |d         d          |d<   t          j        |d          d          |d <   t          j        |d!         d          |d!<   t          j        |d"         d          |d"<   t          j        |d#         d          |d#<   t          j        |d$         d          |d$<   t          j        |d%         d          |d%<   |S )&u  
    天天基金网-基金评级-济安金信评级
    https://fund.eastmoney.com/data/fundrating_4.html
    :param date: 日期; https://fund.eastmoney.com/data/fundrating_4.html 获取查询日期
    :type date: str
    :return: 济安金信评级
    :rtype: pandas.DataFrame
    z1https://fund.eastmoney.com/data/fundrating_4.htmlr   c                     g | ]
}|d          S rH   rJ   r   s     r   r   z"fund_rating_ja.<locals>.<listcomp>   rK   r   rL   r	   rM   rN   r%   NrO   r   uM   请访问 http://fund.eastmoney.com/data/fundrating_4.html 获取查询日期z-https://fund.eastmoney.com/data/fundrating_4_rP   r   r
   r   c                 8    g | ]}|                     d           S r   r   r   s     r   r   z"fund_rating_ja.<locals>.<listcomp>*  r   r   r   r   r   r   r   r   r    )r!   r"   r#   r$   rR   r&   rR   rS   rT   rW   rX   rY   rZ   r[   r\   r,   rR   rR   rR   rR   )r!   r"   r$   r&   rS   rT   rW   rX   rY   rZ   r[   r\   r,   r#   rX   r-   r.   rS   rT   rW   rY   rZ   r[   r\   r]   ra   s	            r   fund_rating_jarm     s    >CSA((D "&))HT;<O)"P"P  I ((D!Hd1Q3iabb:;;K)##]]
j#((D!HdSTUVSViY]^_^`^`YaCb:c:c
j
j
jCSA((D		%j'9	::??IIPI	 	OOE**1-	sA		s	s	s	t	 	 	L l<((G  GO, 	
 	
 	
G$ wx'8JJJMRGH*,-*+H+ + +G&' *,)*8* * *G%& !mGN,CHUUUGN mGN,CHUUUGN!}W_-EhWWWGO!}W_-EhWWWGO!}W_-EhWWWGONr   __main__)rE   )rD   )re   )__doc__pandasr8   r2   bs4r   r9   rC   r<   rd   ri   rm   __name__fund_rating_all_dfprintfund_rating_sh_dffund_rating_zs_dffund_rating_ja_dfrJ   r   r   <module>rx      s              J J J J JZ_ _ _bl _ _ _ _DT T Tbl T T T TnU U Ubl U U U Up z(**	E
&J777	E
&J777	E
&J777	E
 r   