0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

webページ更新 自動検知

Last updated at Posted at 2021-07-22
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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?