我正在尝试从维基百科上抓取数据
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
此代码可以在我朋友的笔记本电脑上完美运行,但无法在我的笔记本上运行。请帮忙! :)
答案 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"))