code: #!/usr/bin/env python
  # -*- coding:utf-8 -*-
  """
  Date: 2021/12/20 14:52
  Desc: 南华期货-商品指数历史走势-价格指数-数值
  http://www.nanhua.net/nhzc/varietytrend.html
  1000 点开始, 用收益率累计
  http://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
  """
  import time
  
  import requests
  import pandas as pd
  
  
  def futures_nh_index_symbol_table() -> pd.DataFrame:
      """
      南华期货-南华指数所有品种一览表
      http://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
      :return: 南华指数所有品种一览表
      :rtype: pandas.DataFrame
      """
      url = "http://www.nanhua.net/ianalysis/plate-variety.json"
      r = requests.get(url)
      data_json = r.json()
      temp_df = pd.DataFrame(data_json)
      temp_df['firstday'] = pd.to_datetime(temp_df['firstday']).dt.date
      return temp_df
  
  
  def futures_nh_price_index(symbol: str = "A") -> pd.DataFrame:
      """
      南华期货-南华指数单品种-价格-所有历史数据
      http://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
      :param symbol: 通过 ak.futures_nh_index_symbol_table() 获取
      :type symbol: str
      :return: 南华期货-南华指数单品种-价格-所有历史数据
      :rtype: pandas.Series
      """
      symbol_df = futures_nh_index_symbol_table()
      if symbol in symbol_df["code"].tolist():
          t = time.time()
          url = f"http://www.nanhua.net/ianalysis/varietyindex/price/{symbol}.json?t={int(round(t * 1000))}"
          r = requests.get(url)
          data_json = r.json()
          temp_df = pd.DataFrame(data_json)
          temp_df.columns = ["date", "value"]
          temp_df['date'] = pd.to_datetime(temp_df["date"], unit='ms').dt.date
          return temp_df
  
  
  if __name__ == "__main__":
      futures_nh_index_symbol_table_df = futures_nh_index_symbol_table()
      print(futures_nh_index_symbol_table_df)
  
      futures_nh_price_index_df = futures_nh_price_index(symbol="NHAI")
      print(futures_nh_price_index_df)
   #!/usr/bin/env python
  # -*- coding:utf-8 -*-
  """
  Date: 2021/9/12 18:29
  Desc: 巨潮资讯-数据中心-评级预测-投资评级
  http://webapi.cninfo.com.cn/#/thematicStatistics?name=%E6%8A%95%E8%B5%84%E8%AF%84%E7%BA%A7
  """
  import time
  from py_mini_racer import py_mini_racer
  import requests
  import pandas as pd
  
  js_str = """
      function mcode(input) {  
                  var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv"   + "wxyz0123456789+/" + "=";  
                  var output = "";  
                  var chr1, chr2, chr3 = "";  
                  var enc1, enc2, enc3, enc4 = "";  
                  var i = 0;  
                  do {  
                      chr1 = input.charCodeAt(i++);  
                      chr2 = input.charCodeAt(i++);  
                      chr3 = input.charCodeAt(i++);  
                      enc1 = chr1 >> 2;  
                      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);  
                      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);  
                      enc4 = chr3 & 63;  
                      if (isNaN(chr2)) {  
                          enc3 = enc4 = 64;  
                      } else if (isNaN(chr3)) {  
                          enc4 = 64;  
                      }  
                      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)  
                              + keyStr.charAt(enc3) + keyStr.charAt(enc4);  
                      chr1 = chr2 = chr3 = "";  
                      enc1 = enc2 = enc3 = enc4 = "";  
                  } while (i < input.length);  
            
                  return output;  
              }  
  """
  
  
  def stock_rank_forecast_cninfo(date: str = "20210910") -> pd.DataFrame:
      """
      巨潮资讯-数据中心-评级预测-投资评级
      http://webapi.cninfo.com.cn/#/thematicStatistics?name=%E6%8A%95%E8%B5%84%E8%AF%84%E7%BA%A7
      :param date: 查询日期
      :type date: str
      :return: 投资评级
      :rtype: pandas.DataFrame
      """
      url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1089"
      params = {"tdate": "-".join([date[:4], date[4:6], date[6:]])}
      random_time_str = str(int(time.time()))
      js_code = py_mini_racer.MiniRacer()
      js_code.eval(js_str)
      mcode = js_code.call("mcode", random_time_str)
      headers = {
          "Accept": "*/*",
          "Accept-Encoding": "gzip, deflate",
          "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
          "Cache-Control": "no-cache",
          "Content-Length": "0",
          "Host": "webapi.cninfo.com.cn",
          "mcode": mcode,
          "Origin": "http://webapi.cninfo.com.cn",
          "Pragma": "no-cache",
          "Proxy-Connection": "keep-alive",
          "Referer": "http://webapi.cninfo.com.cn/",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36",
          "X-Requested-With": "XMLHttpRequest",
      }
      r = requests.post(url, params=params, headers=headers)
      data_json = r.json()
      temp_df = pd.DataFrame(data_json["records"])
      temp_df.columns = [
          "证券简称",
          "发布日期",
          "前一次投资评级",
          "评级变化",
          "目标价格-上限",
          "是否首次评级",
          "投资评级",
          "研究员名称",
          "研究机构简称",
          "目标价格-下限",
          "证券代码",
      ]
      temp_df = temp_df[[
          "证券代码",
          "证券简称",
          "发布日期",
          "研究机构简称",
          "研究员名称",
          "投资评级",
          "是否首次评级",
          "评级变化",
          "前一次投资评级",
          "目标价格-下限",
          "目标价格-上限",
      ]]
      temp_df["目标价格-上限"] = pd.to_numeric(temp_df["目标价格-上限"], errors="coerce")
      temp_df["目标价格-下限"] = pd.to_numeric(temp_df["目标价格-下限"], errors="coerce")
      return temp_df
  
  
  if __name__ == "__main__":
      stock_rank_forecast_cninfo_df = stock_rank_forecast_cninfo(date="20210907")
      print(stock_rank_forecast_cninfo_df)
   #!/usr/bin/env python
  # -*- coding:utf-8 -*-
  """
  Date: 2021/12/27 15:47
  Desc: 中国公路物流运价、运量指数
  http://index.0256.cn/expx.htm
  """
  import pandas as pd
  import requests
  
  
  def index_cflp_price(symbol: str = "周指数") -> pd.DataFrame:
      """
      中国公路物流运价指数
      http://index.0256.cn/expx.htm
      :param symbol: choice of {"周指数", "月指数", "季度指数", "年度指数"}
      :type symbol: str
      :return: 中国公路物流运价指数
      :rtype: pandas.DataFrame
      """
      symbol_map = {
          "周指数": "2",
          "月指数": "3",
          "季度指数": "4",
          "年度指数": "5",
      }
      url = "http://index.0256.cn/expcenter_trend.action"
      params = {
          "marketId": "1",
          "attribute1": "5",
          "exponentTypeId": symbol_map[symbol],
          "cateId": "2",
          "attribute2": "华北",
          "city": "",
          "startLine": "",
          "endLine": "",
      }
      headers = {
          "Origin": "http://index.0256.cn",
          "Referer": "http://index.0256.cn/expx.htm",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
      }
      r = requests.post(url, data=params, headers=headers)
      data_json = r.json()
      temp_df = pd.DataFrame(
          [
              data_json["chart1"]["xLebal"],
              data_json["chart1"]["yLebal"],
              data_json["chart2"]["yLebal"],
              data_json["chart3"]["yLebal"],
          ]
      ).T
      temp_df.columns = ["日期", "定基指数", "环比指数", "同比指数"]
      temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date
      temp_df["定基指数"] = pd.to_numeric(temp_df["定基指数"])
      temp_df["环比指数"] = pd.to_numeric(temp_df["环比指数"])
      temp_df["同比指数"] = pd.to_numeric(temp_df["同比指数"])
      return temp_df
  
  
  def index_cflp_volume(symbol: str = "月指数") -> pd.DataFrame:
      """
      中国公路物流运量指数
      http://index.0256.cn/expx.htm
      :param symbol: choice of {"月指数", "季度指数", "年度指数"}
      :type symbol: str
      :return: 中国公路物流运量指数
      :rtype: pandas.DataFrame
      """
      symbol_map = {
          "月指数": "3",
          "季度指数": "4",
          "年度指数": "5",
      }
      url = "http://index.0256.cn/volume_query.action"
      params = {
          "type": "1",
          "marketId": "1",
          "expTypeId": symbol_map[symbol],
          "startDate1": "",
          "endDate1": "",
          "city": "",
          "startDate3": "",
          "endDate3": "",
      }
      headers = {
          "Origin": "http://index.0256.cn",
          "Referer": "http://index.0256.cn/expx.htm",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
      }
      r = requests.post(url, data=params, headers=headers)
      data_json = r.json()
      temp_df = pd.DataFrame(
          [
              data_json["chart1"]["xLebal"],
              data_json["chart1"]["yLebal"],
              data_json["chart2"]["yLebal"],
              data_json["chart3"]["yLebal"],
          ]
      ).T
      temp_df.columns = ["日期", "定基指数", "环比指数", "同比指数"]
      temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date
      temp_df["定基指数"] = pd.to_numeric(temp_df["定基指数"])
      temp_df["环比指数"] = pd.to_numeric(temp_df["环比指数"])
      temp_df["同比指数"] = pd.to_numeric(temp_df["同比指数"])
      return temp_df
  
  
  if __name__ == "__main__":
      index_cflp_price_df = index_cflp_price(symbol="周指数")
      print(index_cflp_price_df)
  
      index_cflp_price_df = index_cflp_price(symbol="月指数")
      print(index_cflp_price_df)
  
      index_cflp_price_df = index_cflp_price(symbol="季度指数")
      print(index_cflp_price_df)
  
      index_cflp_price_df = index_cflp_price(symbol="年度指数")
      print(index_cflp_price_df)
  
      index_cflp_volume_df = index_cflp_volume(symbol="月指数")
      print(index_cflp_volume_df)
  
      index_cflp_volume_df = index_cflp_volume(symbol="季度指数")
      print(index_cflp_volume_df)
  
      index_cflp_volume_df = index_cflp_volume(symbol="年度指数")
      print(index_cflp_volume_df)
  
apis: pandas.to_datetime pandas.DataFrame
apis: pandas.to_numeric pandas.DataFrame
apis: pandas.to_numeric pandas.to_datetime pandas.DataFrame