如何将HTML表格读取为资料框(urllib.error.URLError:<urlopen error =“” unknown =“” url =“” type:=“” https =“”>)?

时间:2019-02-03 12:10:14

标签: python-3.x pandas

如果您能让我知道如何将html表转换为数据框,我将不胜感激。

import pandas as pd
df = pd.read_html('https://www.iasplus.com/en/resources/ifrs-topics/use-of-ifrs', header = None)

错误:

C:\Users\t\Anaconda3\python.exe C:/Users/t/Downloads/hyperopt12.py
Traceback (most recent call last):
  File "C:/Users/t/Downloads/hyperopt12.py", line 12, in <module>
    df = pd.read_html('https://www.iasplus.com/en/resources/ifrs-topics/use-of-ifrs', header = None)
  File "C:\Users\t\Anaconda3\lib\site-packages\pandas\io\html.py", line 1094, in read_html
    displayed_only=displayed_only)
  File "C:\Users\t\Anaconda3\lib\site-packages\pandas\io\html.py", line 916, in _parse
    raise_with_traceback(retained)
  File "C:\Users\t\Anaconda3\lib\site-packages\pandas\compat\__init__.py", line 420, in raise_with_traceback
    raise exc.with_traceback(traceback)
urllib.error.URLError: <urlopen error unknown url type: https>

谢谢。

1 个答案:

答案 0 :(得分:0)

您需要在页面上找到正确的表格才能阅读。 read_html返回数据框对象的列表。请参阅文档here

import pandas as pd
tables = pd.read_html('https://www.iasplus.com/en/resources/ifrs-topics/use-of-ifrs', header = None)
df = tables[2]
df