再起動後にシームレスに再開するために、Web ページに変更が加えられたときに通知し、ページの現在の状態をファイルに保存する Python スクリプトを作成しています。コードは次のとおりです。
import urllib
url="http://example.com"
filepath="/path/to/file.txt"
try:
html=open(filepath,"r").read() # Restores imported code from previous session
except:
html="" # Blanks variable on first run of the script
while True:
imported=urllib.urlopen(url)
if imported!=html:
# Alert me
html=imported
open(filepath,"w").write(html)
# Time delay before next iteration
スクリプトを実行すると、以下が返されます。
Traceback (most recent call last):
File "April_Fools.py", line 20, in <module>
open(filepath,"w").write(html)
TypeError: expected a character buffer object
------------------
(program exited with code: 1)
Press return to continue
これが何を意味するのかわかりません。私はPythonに比較的慣れていません。どんな助けでも大歓迎です。