Apr-11-2022, 08:57 PM
Yes,can eg save the the state of want to check to disk.
from bs4 import BeautifulSoup html = '''\ <body> <h1>The img element</h1> <img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600"> </body> </html>''' soup = BeautifulSoup(html, 'lxml') img_tag = soup.select_one('img')['alt'] # Girl in a jacket with open('img_tag.txt', 'w') as f_out: f_out.write(img_tag)Then check like this.
from bs4 import BeautifulSoup html = '''\ <body> <h1>The img element</h1> <img src="img_girl.jpg" alt="Apple in snow" width="500" height="600"> </body> </html>''' soup = BeautifulSoup(html, 'lxml') img_tag = soup.select_one('img')['alt'] with open('img_tag.txt') as f: old_tag = f.read() if old_tag == img_tag: print('No update') else: print(f'New image update: <{img_tag}>')
Output:New image update: <Apple in snow>
Can run manually or automate in a schedule way eg Python job scheduling for humans.