我正试图从维基百科中抓取数据
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
这个代码在我朋友的笔记本电脑上运行得很好,但在我的电脑上运行不起来。请帮忙!:(
我建议您尝试在转储函数调用后刷新输入,如
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"))