EOFError:尝试从Wikipedia抓取数据时跑出输入

时间:2018-12-15 01:12:11

标签: python python-3.x

我正在尝试从维基百科上抓取数据

if refresh:
    page = 'https://en.wikipedia.org/wiki/Farebox_recovery_ratio'
    wikitables = read_html(page)
    table = wikitables[1]
    pickle.dump(table, open(r"wiki_table.pkl", "wb"))
else:
    table = pickle.load(open(r"wiki_table.pkl", "rb"))

这是我在终端上收到的错误消息

Traceback (most recent call last):
  File "judy.py", line 16, in <module>
    table = pickle.load(open(r"wiki_table.pkl", "rb"))
EOFError: Ran out of input

此代码可以在我朋友的笔记本电脑上完美运行,但无法在我的笔记本上运行。请帮忙! :)

1 个答案:

答案 0 :(得分:0)

我建议您在这样的转储函数调用之后尝试刷新输入

if refresh:
    page = 'https://en.wikipedia.org/wiki/Farebox_recovery_ratio'
    wikitables = read_html(page)
    table = wikitables[1]
    with open(r"wiki_table.pkl", "wb") as result_file:
        pickle.dump(table, result_file)
        result_file.flush()
else:
    table = pickle.load(open(r"wiki_table.pkl", "rb"))