from bs4 import BeautiflSoup
import requests
#urlからDOMの抽出
url = ''
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
#更新を検知する要素を取得
new_elem = str(soup.select(''))
#txtファイルから以前の状態を読み込み
try:
with open('old_elem.txt') as f:
old_elem = f.read()
except:
old_elem = ''
#以前の状態と取得した状態を比較
if new_elem == old_elem:
print('更新なし')
return False
else:
with open('old_elem.txt' 'w') as f:
f.write(new_elem)
print('更新あり')
return True
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme