akfamily / akshare

AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
https://akshare.akfamily.xyz
MIT License
9.09k stars 1.86k forks source link

AKShare 接口问题报告 #2946

Closed c7h12 closed 2 years ago

c7h12 commented 2 years ago

遇到任何问题,请先确认您的 AKShare 版本是最新的

pip install akshare --upgrade  # Python 版本需要大于 3.7

描述遇到的问题

  1. 操作系统版本
    macos BigSur 11.6.8
  2. Python 版本
    conda>Python 3.8.12
  3. AKShare 版本
    1.7.22
  4. 接口的名称和代码
    
    import akshare as ak

print(ak.index_investing_global())

5. 接口报错的截图或代码

In [1]: import akshare as ak

In [2]: ak.version Out[2]: '1.7.22'

In [3]: ak.index_investing_global()

AttributeError Traceback (most recent call last) Input In [3], in <cell line: 1>() ----> 1 ak.index_investing_global()

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:162, in index_investing_global(area, symbol, period, start_date, end_date) 160 end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]]) 161 period_map = {"每日": "Daily", "每周": "Weekly", "每月": "Monthly"} --> 162 name_code_dict = index_investing_global_area_index_name_code(area) 163 url = f"https://api.investing.com/api/financialdata/historical/{name_code_dict[symbol]}" 164 params = { 165 "start-date": start_date, 166 "end-date": end_date, 167 "time-frame": period_map[period], 168 "add-missing-rows": "false", 169 }

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:89, in index_investing_global_area_index_name_code(area) 87 scraper = cfscrape.create_scraper(delay=10) 88 pd.set_option("mode.chained_assignment", None) ---> 89 name_url_dict = _get_global_country_name_url() 90 url = f"https://cn.investing.com{name_url_dict[area]}?&majorIndices=on&primarySectors=on&additionalIndices=on&otherIndices=on" 91 r = scraper.get(url)

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:66, in _get_global_country_name_url() 64 res = session.post(url, headers=short_headers) 65 soup = BeautifulSoup(res.text, "lxml") ---> 66 name_url_option_list = soup.find( 67 "select", attrs={"name": "country"} 68 ).find_all("option")[ 69 1: 70 ] # 去掉-所有国家及地区 71 url_list = [item["value"] for item in name_url_option_list] 72 name_list = [item.get_text() for item in name_url_option_list]

AttributeError: 'NoneType' object has no attribute 'find_all'

6. 期望获得的正确结果
albertandking commented 2 years ago

遇到任何问题,请先确认您的 AKShare 版本是最新的

pip install akshare --upgrade  # Python 版本需要大于 3.7

描述遇到的问题

  1. 操作系统版本
   macos BigSur 11.6.8
  1. Python 版本
conda>Python 3.8.12
  1. AKShare 版本
1.7.22
  1. 接口的名称和代码
import akshare as ak

print(ak.index_investing_global())
  1. 接口报错的截图或代码
In [1]: import akshare as ak

In [2]: ak.__version__
Out[2]: '1.7.22'

In [3]: ak.index_investing_global()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 ak.index_investing_global()

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:162, in index_investing_global(area, symbol, period, start_date, end_date)
    160 end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
    161 period_map = {"每日": "Daily", "每周": "Weekly", "每月": "Monthly"}
--> 162 name_code_dict = index_investing_global_area_index_name_code(area)
    163 url = f"https://api.investing.com/api/financialdata/historical/{name_code_dict[symbol]}"
    164 params = {
    165     "start-date": start_date,
    166     "end-date": end_date,
    167     "time-frame": period_map[period],
    168     "add-missing-rows": "false",
    169 }

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:89, in index_investing_global_area_index_name_code(area)
     87 scraper = cfscrape.create_scraper(delay=10)
     88 pd.set_option("mode.chained_assignment", None)
---> 89 name_url_dict = _get_global_country_name_url()
     90 url = f"https://cn.investing.com{name_url_dict[area]}?&majorIndices=on&primarySectors=on&additionalIndices=on&otherIndices=on"
     91 r = scraper.get(url)

File ~/opt/miniconda3/envs/zero-dev/lib/python3.8/site-packages/akshare/index/index_investing.py:66, in _get_global_country_name_url()
     64 res = session.post(url, headers=short_headers)
     65 soup = BeautifulSoup(res.text, "lxml")
---> 66 name_url_option_list = soup.find(
     67     "select", attrs={"name": "country"}
     68 ).find_all("option")[
     69     1:
     70 ]  # 去掉-所有国家及地区
     71 url_list = [item["value"] for item in name_url_option_list]
     72 name_list = [item.get_text() for item in name_url_option_list]

AttributeError: 'NoneType' object has no attribute 'find_all'
  1. 期望获得的正确结果

通过代理访问