Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- from datetime import datetime
- def search_string_in_webpage(url, search_string):
- try:
- response = requests.get(url)
- response.raise_for_status()
- content = response.text
- if search_string in content:
- return 1
- else:
- return 0
- except requests.RequestException as e:
- print(f"Error fetching the webpage: {e}")
- return 0
- url = "https://eu.store.ui.com/eu/en/products/utr"
- search_string = "Sold Out"
- while True:
- result = search_string_in_webpage(url, search_string)
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- if result == 1:
- with open("soldout.txt", "a") as f:
- f.write(f"{timestamp}\n")
- print(f"{timestamp} - Found! Logged to soldout.txt")
- else:
- with open("instock.txt", "a") as f:
- f.write(f"{timestamp}\n")
- print(f"{timestamp} - Not found. Logged to instock.txt")
- time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment