-
-
Save pa-0/caefd60f3da647abe3272f1b6b8a71e9 to your computer and use it in GitHub Desktop.
Basic web scraping monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from bs4 import BeautifulSoup | |
| import time | |
| def update(): | |
| request = requests.get('https://mathewsteininger.com/sample-product') | |
| html = request.content | |
| soup = BeautifulSoup(html, 'html.parser') | |
| # Monitor this tag to check stock changes | |
| stock = soup.find("button", {"id": "availability"}) | |
| # Monitor this tag to check price changes | |
| price = soup.find("div", {"id": "price"}) | |
| return stock, price | |
| stock, price = update() | |
| while True: | |
| time.sleep(2) | |
| updated_stock, updated_price = update() | |
| if (stock, price) != (updated_stock, updated_price): | |
| # Could connect notification API here | |
| print("Price or Stock Changed!") | |
| stock, price = updated_stock, updated_price | |
| else: | |
| print("No Update") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment